简体   繁体   English

使用Python Pandas,读取xlsx文件中写入的多个文件夹路径,分别处理每个csv文件

[英]Using Python Pandas, read multiple folder paths written in xlsx file and process each csv file separately

I have an excel file with the name F_Path.xlsx listing the folder paths like below:我有一个名为 F_Path.xlsx 的 excel 文件,其中列出了如下文件夹路径: 在此处输入图像描述

path = "C:/Users/Axel/Documents/Work/F_Path.xlsx" 
df_input = pd.read_excel(path1, sheet_name=0) #reading the excel file
folder_path = list(df_input['Folder Path']
path_csv = #1st csv file from C:/Users/Axel/Documents/Work/Folder_1, then 2nd read in for loop, but don't know how.. once all the csv are read from Folder_1, it has to read folder_path[1 to n] and read all the csv files and process it separately.

.
.
.
.
.
df = pd.read_csv(path_csv)  # read all the *.csv file one by one and process each df separately.

#process the data

Try the following:尝试以下操作:

# you'll need to import os
import os

# loop your folders
for folder in folder_path:
    # get the csvs in that folder
    csv_files = os.listdir(folder)
    # loop the csvs
    for csvfile in csv_files:
        df = pd.read_csv(os.path.join(folder, csvfile))
        # do your processing here

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 stream 读取 CSV 文件并在写入时处理每一行? - How to read a CSV file from a stream and process each line as it is written? 熊猫从CSV生成多个xlsx文件 - Pandas Generate Multiple xlsx file from CSV 使用 Python 中的 Pandas 库读取 .xlsx 文件时出错? - Error in read a .xlsx file using the pandas Library in Python? 使用 Pandas 从 Python CGI 脚本中上传的 XLSX 文件中读取 - Read from uploaded XLSX file in Python CGI script using Pandas 使用 Python/Pandas 循环遍历文件夹中的多个 csv 文件并对每个 csv 文件进行更改 - Using Python/Pandas to loop over several csv files in a folder and make changes to each csv file 如何使用Google Colab python读取/循环文件夹中的多个.csv文件,然后将每个文件分配为函数参数 - How to read/loop through multiple .csv files in a folder using Google Colab python, then assign each file as a function parameter 如何使用 Python 中的 pandas 读取 csv 文件? - How to read a csv file using pandas in Python? 使用 pandas 正确读取 python 中的 csv 文件 - Read a csv file in python correctly using pandas 使用python将大型xlsx拆分为多个csv文件 - split large xlsx to multiple csv file using python 我需要使用 python 中的 pandas 拆分 csv 数据库中的数据,并将其写入具有多张工作表的 xlsx 文件,并创建一个额外的 col - I need to split data in a csv database using pandas in python and write it to and xlsx file with multiple sheets as well as creating an additional col
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM