[英]Multiple sheets of an Excel workbook into different dataframes using Pandas
I have a Excel workbook which has 5 sheets containing data.我有一个 Excel 工作簿,其中有 5 个包含数据的工作表。 I want each sheet to be a different dataframe.我希望每张纸都是不同的 dataframe。
I tried using the below code for one sheet of my Excel Sheet我尝试对我的 Excel 表中的一张使用以下代码
df = pd.read_excel("path",sheet_name = ['Product Capacity'])
df
But this returns the sheet as a dictionary of the sheet, not a dataframe.但这会将工作表作为工作表的字典返回,而不是 dataframe。
I need a data frame.我需要一个数据框。 Please suggest the code that will return a dataframe请建议将返回 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']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.