如何在 Python 中从我的 XLS 文件中读取特定的工作表

新手上路,请多包涵

截至目前,我可以阅读 EXCEL 文件的所有表格。

 e.msgbox("select Excel File")
updated_deleted_xls = e.fileopenbox()
book = xlrd.open_workbook(updated_deleted_xls, formatting_info=True)
openfile = e.fileopenbox()
for sheet in book.sheets():
for row in range(sheet.nrows):
for col in range(sheet.ncols):
thecell = sheet.cell(row, 0)
xfx = sheet.cell_xf_index(row, 0)
xf = book.xf_list[xfx]

原文由 user3698866 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 815
1 个回答

如果您从桌面或命令行打开编辑器,则在尝试读取文件时必须指定文件路径:

 import pandas as pd
df = pd.read_excel(r'File path', sheet_name='Sheet name')

或者,如果您在文件目录中打开编辑器,则可以直接使用 panda 库进行读取

import pandas as pd
df = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='Title Sheet')
df1 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx',sheet_name='Transactions')
df2 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='NewCustomerList')
df3 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='CustomerDemographic')
df4 = pd.read_excel('KPMG_VI_New_raw_data_update_final.xlsx', sheet_name='CustomerAddress')

原文由 muyiwa davis 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题