简体   繁体   English

使用 Pandas 将 Excel 工作簿的多张工作表放入不同的数据框中

[英]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.

相关问题 Python / Pandas:使用“for-loop”将多个Dataframes写入Excel工作表 - Python/Pandas: writing multiple Dataframes to Excel sheets using a “for-loop” Pandas to_excel() - 无法弄清楚如何使用 for 循环将多个数据帧导出为一个 excel 中的不同工作表 - Pandas to_excel() - can't figure out how to export multiple dataframes as different sheets in one excel using for loop 无法使用 XlsxWriter 将多个 DataFrame 导出到 Excel 中的不同工作表 - Can't export multiple DataFrames to different sheets in Excel using XlsxWriter 将 2 个 Dataframes 组合成 1 个 excel 工作簿和 2 个工作表 - Combining 2 Dataframes into 1 excel workbook with 2 sheets 将多个数据框附加到不同的工作表上 - Appending multiple dataframes to excel on different sheets 使用 pandas 从同一工作簿中的多个 excel 工作表中提取部分数据 - Extract Partial Data from multiple excel sheets in the same workbook using pandas 在多个Excel工作表的同一索引上附加熊猫数据框 - Appending pandas dataframes on same index from multiple excel sheets Python 和 Pandas 使用数据框创建多个动态 Excel 工作表 - Python and Pandas Creating Multiple Dynamic Excel Sheets with Dataframes 将多个文本文件写入不同工作表上的一个excel工作簿? - Write multiple text files to one excel workbook on different sheets? 将数据框写入不同的 Excel 表格 - Writing Dataframes to Different excel Sheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM