且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python将多个excel中的所有工作表附加到pandas数据框中的有效方法

更新时间:2022-05-24 00:27:16

read_excel 用于返回从所有工作表名称创建的 DataFrames 的 orderdict,然后通过 concat 和最后一个 DataFrame.append 到最终DataFrame:

Use sheet_name=None in read_excel for return orderdict of DataFrames created from all sheetnames, then join together by concat and last DataFrame.append to final DataFrame:

out_df = pd.DataFrame()
for f in source_dataset_list:
    df = pd.read_excel(f, sheet_name=None)
    cdf = pd.concat(df.values())
    out_df = out_df.append(cdf,ignore_index=True)

另一种解决方案:

cdf = [pd.read_excel(excel_names, sheet_name=None).values() 
            for excel_names in source_dataset_list]

out_df = pd.concat([pd.concat(x) for x in cdf], ignore_index=True)