我有一个约10个CSV文件的数据集。我想将这些文件逐行组合成一个CSV文件。如何使用python逐行连接多个CSV文件?
我试了一下:
import csv
fout = open("claaassA.csv","a")
# first file:
writer = csv.writer(fout)
for line in open("a01.ihr.60.ann.csv"):
print line
writer.writerow(line)
# now the rest:
for num in range(2, 10):
print num
f = open("a0"+str(num)+".ihr.60.ann.csv")
#f.next() # skip the header
for line in f:
print line
writer.writerow(line)
#f.close() # not really needed
fout.close()
您的CSV文件是否具有相同的列名和订单? – Fomalhaut
这个答案如何:http://stackoverflow.com/questions/2512386/how-to-merge-200-csv-files-in-python –
发布一些csv数据将有所帮助 –