简体   繁体   中英

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.

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

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM