[英]Merging hundreds excel file with path reference into one pandas dataframe
I have probably hundreds or thousands small excel file with bracket into one pandas dataframe我可能有成百上千个带括号的小 excel 文件到一个熊猫数据框中
Here's my table of reference df
这是我的参考表
df
Dataframe_name Path Sheet
45 finance_auditing Finance - Accounting/TopSites-Fin... Aggregated_Data_for_Time_Period
46 finance_lending Finance - Banking/TopSites-... Aggregated_Data_for_Time_Period
What I did我做了什么
finance_auditing = pd.read_excel('Finance - Accounting/TopSites-Fin... ','Aggregated_Data_for_Time_Period')
finance_lending = pd.read_excel('Finance - Banking/TopSites-... ','Aggregated_Data_for_Time_Period')
all = finance_auditing.append(finance_lending)
The problem is I have hundreds of of file to read and need to append them all问题是我有数百个文件要读取并且需要全部附加
You can use list comprehension to iterate over the pairs of path and sheet and read the corresponding excel file, finally concat
all the excel files:您可以使用列表推导来遍历路径和工作表对并读取相应的 excel 文件,最后
concat
所有 excel 文件:
pd.concat([pd.read_excel(path, sheet_name=sheet)
for path, sheet in zip(df.Path, df.Sheet)])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.