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