我正在用Python编写代码,并希望就如何将它们写入具有特定格式的csv文件提出一些建议。 数据:
Dataset1: 2,4,6,8,10,12,14,16,18,20
Dataset2: 6,16
CSV文件中的所需输出:
Value1 Value2 Value3 Value4 Value5
2 4 6 8 10
Average Value: 6
12 14 16 18 20
Average Value: 16
尝试代码:
import csv
with open(OutFile, 'wb') as csv_file:
writer = csv.writer(csv_file, delimiter = ',')
for row in data1:
for row2 in data2:
writer.writerow(row)
writer.writerow(row2)