如何在Python中合并200个csv文件
问题内容:
伙计们,我这里有200个独立的csv文件,分别从SH(1)命名为SH(200)。我想将它们合并到单个csv文件中。我该怎么做?
问题答案:
正如ghostdog74所说的,但是这次有标题:
fout=open("out.csv","a")
# first file:
for line in open("sh1.csv"):
fout.write(line)
# now the rest:
for num in range(2,201):
f = open("sh"+str(num)+".csv")
f.next() # skip the header
for line in f:
fout.write(line)
f.close() # not really needed
fout.close()