Excel file overwritten instead of concat - Python - Pandas

后端 未结 3 1153
情话喂你
情话喂你 2021-01-16 05:44

I\'m trying to contact all excel files and worksheets in them into one using the below script. It kinda works but then the excel file c.xlsx is overwritten per file, so only

3条回答
  •  生来不讨喜
    2021-01-16 06:05

    Idea is create list of DataFrames in list comprehension, but because working with orderdict is necessary concat in loop and then again concat for one big final DataFrame:

    cdf = [pd.read_excel(excel_names, sheet_name=None, ignore_index=True).values() 
           for excel_names in glob.glob('files/*.xlsx')]
    
    df = pd.concat([pd.concat(x) for x in cdf], ignore_index=True)
    #print (df)
    
    df.to_excel("c.xlsx", index=False)
    

提交回复
热议问题