'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

Here's my table of reference 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



Solution 1:[1]

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:

pd.concat([pd.read_excel(path, sheet_name=sheet) 
           for path, sheet in zip(df.Path, df.Sheet)])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1