Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple sheets of an Excel workbook into different dataframes using Pandas

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading