【发布时间】:2019-06-05 05:09:44
【问题描述】:
我想将工作簿中的 Excel 表格(使用 Excel 2007 及更高版本的制表功能制作)导入单独的数据框。抱歉,如果之前有人问过这个问题,但从我的搜索中我找不到我想要的东西。我知道您可以使用 read_excel 函数轻松地做到这一点,但是这个 requires the specification of a Sheetname 或 returns a dict of dataframes for each sheet。
我想知道是否有一种方法可以指定表名,或者更好地为工作簿中的每个表返回一个数据框字典,而不是指定工作表名。
我知道这可以通过combining xlwings with pandas 完成,但想知道这是否已经内置在任何 pandas 函数中(可能是 ExcelFile)。
类似这样的:-
import pandas as pd
xls = pd.ExcelFile('excel_file_path.xls')
# to read all tables to a map
tables_to_df_map = {}
for table_name in xls.table_names:
table_to_df_map[table_name] = xls.parse(table_name)
【问题讨论】:
-
也许这回答了你的问题? stackoverflow.com/questions/26521266/…
-
@Manrique 感谢他的建议。我昨天发现了该帖子,但它仅与我不感兴趣的工作表加载相关。我对加载 Excel 表格感兴趣(使用转换为表格工具在 excel 中创建)。
标签: python excel pandas dataframe