简体   繁体   English

如何在python中的文件夹中读取某些csv文件

[英]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.

相关问题 使用 python,如何读取文件夹中的所有 CSV 文件并将其内容写入新的单个 CSV 文件? - Using python, how to read all the CSV files in a folder and write the content of the same to a new single CSV file? 如何将文件夹中存在的 .mp4 文件与 .csv 文件中的名称相匹配,并在 python 中根据某些列值进行排序? - How to match the .mp4 files present in a folder with the names in .csv file and sort according to some column value, in python? 如何使用 Python 将文件夹中的所有 csv 文件加入? - How to join all csv files in a folder with Python? 如何从包含 python 中的多个 csv 文件的文件夹中一次读取一个文件 - How to read one file at a time from folder that contains multiple csv files in python 从文件夹python中的csv文件读取并追加第n行 - Read and append each nth row from csv files in a folder python Python - 从文件夹读取文件并以格式写入 CSV 文件 - Python - Read files from folder and Write CSV file in format Python:读取我的文件夹中的多个但不是全部的csv文件 - Python: read through multiple but not all csv files in my folder 直接在 Python 中从网站 rar 文件夹中读取 csv 文件 - Read csv files from website rar folder directly in Python 读取一个文件夹中的多个 csv 文件 - Read multiple csv files in a folder 读取文件夹中的特定 CSV 文件? - Read specific CSV files in a folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM