pandas Combine Excel Spreadsheets

后端 未结 2 1521
日久生厌
日久生厌 2020-12-10 15:44

I have an Excel workbook with many tabs. Each tab has the same set of headers as all others. I want to combine all of the data from each tab into one data frame (without rep

2条回答
  •  醉酒成梦
    2020-12-10 16:35

    This is one way to do it -- load all sheets into a dictionary of dataframes and then concatenate all the values in the dictionary into one dataframe.

    import pandas as pd
    

    Set sheetname to None in order to load all sheets into a dict of dataframes and ignore index to avoid overlapping values later (see comment by @bunji)

    df = pd.read_excel('tmp.xlsx', sheet_name=None, index_col=None)
    

    Then concatenate all dataframes

    cdf = pd.concat(df.values())
    
    print(cdf)
    

提交回复
热议问题