问题
There are 40 csv files; file1.csv, file2.csv. ..., file40.csv in a folder called pathImage. I want to read them, and put them in another csv file sequentially that we called 'output.csv'. The following code does not work for me.
im_list=[]
for i in pathImage:
f= open(i, 'rb')
reader = csv.reader(f, delimiter=',')
header = reader.next()
zipped = zip(*reader)
for j in zipped[0]: #zipped[0] is the name of images
im_r=misc.imread("%s.png" %j)
im_list.append(im_r)
I already read the previous questions, but I do not know how can I put them into another csv file?
I appreciate any help
回答1:
import pandas as pd
df = pd.concat([pd.read_csv('file%d.csv' % x) for x in range(1,41)])
df.to_csv('output.csv')
来源:https://stackoverflow.com/questions/31620829/how-to-read-some-csv-files-in-a-folder-in-python