Multiple sheets of an Excel workbook into different dataframes using Pandas

Advertisements

I have a Excel workbook which has 5 sheets containing data.
I want each sheet to be a different dataframe.

I tried using the below code for one sheet of my Excel Sheet

df = pd.read_excel("path",sheet_name = ['Product Capacity'])
df

But this returns the sheet as a dictionary of the sheet, not a dataframe.

I need a data frame.
Please suggest the code that will return a dataframe

>Solution :

If you want separate dataframes without dictionary, you have to read individual sheets:

with pd.ExcelFile('data.xlsx') as xlsx:
    prod_cap = pd.read_excel(xlsx, sheet_name='Product Capacity')
    load_cap = pd.read_excel(xlsx, sheet_name='Load Capacity')
    # and so on

But you can also load all sheets and use a dict:

dfs = pd.read_excel('data.xlsx', sheet_name=None)
# dfs['Product Capacity']
# dfs['Load Capacity']

Leave a ReplyCancel reply