Excel file overwritten instead of concat - Python - Pandas

后端 未结 3 1186
情话喂你
情话喂你 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 05:56

    I just tested the code below. It merges data from all Excel files in a folder into one, single, Excel file.

    import pandas as pd
    import numpy as np
    
    import glob
    glob.glob("C:\\your_path\\*.xlsx")
    
    all_data = pd.DataFrame()
    for f in glob.glob("C:\\your_path\\*.xlsx"):
        df = pd.read_excel(f)
        all_data = all_data.append(df,ignore_index=True)
    print(all_data)
    df = pd.DataFrame(all_data)
    df.shape
    df.to_excel("C:\\your_path\\final.xlsx", sheet_name='Sheet1')
    

提交回复
热议问题