几天来我一直在解决这个问题:
import glob
import csv
with open('result.csv', 'w', newline='') as f_output:
csv_output = csv.writer(f_output)
for filename in glob.glob('F*.csv'):
print (filename)
with open (filename, newline='') as f_input:
csv_input = csv.reader(f_input)
header = next(csv_input)
averages = [] #making a list for averages
for col in zip(*csv_input):
averages.append(sum(float(x) for (x) in col) / len(col))
csv_output.writerow([filename] + averages)
df = pd.read_csv(df,skiprows=0, nrows = 18) #to get only first 18 minutes'
但这是1)不起作用(我认为这不适用于读者)2)不是理想的,因为我实际上只想将所有dfs分成18行的块,然后计算每行的平均值。
任何提示都会非常有帮助,谢谢!
而不是使用for循环,我建议加载整个数据帧并使用groupby
: