我有一个 csv 文件,它只有一列,作为我的输入。
我使用该输入来查找我的输出。我有多个输出,我需要另一个 csv 文件中的这些输出。
任何人都可以建议我如何做吗?
这是代码:
import urllib.request
jd = {input 1}
//
Some Codes to find output - a,b,c,d,e
//
** Code to write output to a csv file.
** Repeat the code with next input of input csv file.
Input CSV File has only a single column and is represented below:
1
2
3
4
5
Output would in a separate csv in a given below format :
It would be in multiple rows and multiple columns format.
a b c d e
这是一个简单的例子:
data.csv 是一列多行的 csv。
results.csv 包含输入的平均值和中位数,是一个 1 行 2 列的 csv(平均值在第一列,中位数在第二列)
例子:
import numpy as np
import pandas as pd
import csv
#load the data
data = pd.read_csv("data.csv", header=None)
#calculate things for the 1st column that has the data
calculate_mean = [np.mean(data.loc[:,0])]
calculate_median = [np.median(data.loc[:,0])]
results = [calculate_mean, calculate_median]
#write results to csv
row = []
for result in results:
row.append(result)
with open("results.csv", "wb") as file:
writer = csv.writer(file)
writer.writerow(row)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句