[英]How to read some csv files in a folder in python
There are 40 csv files; 有40个csv文件; file1.csv, file2.csv.
file1.csv,file2.csv。 ..., file40.csv in a folder called pathImage.
...,名为pathImage的文件夹中的file40.csv。 I want to read them, and put them in another csv file sequentially that we called 'output.csv'.
我想阅读它们,并将它们依次放入另一个名为“ output.csv”的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? 我已经阅读了前面的问题,但是不知道如何将它们放入另一个csv文件中?
I appreciate any help 感谢您的帮助
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.