python - 如何在 Python 中从 My XLS 文件中读取特定工作表

标签 python excel xlsx

现在我可以阅读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]

最佳答案

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

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

关于python - 如何在 Python 中从 My XLS 文件中读取特定工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48663698/

相关文章:

r - 编辑 xlsx 的作者

excel - 具有标准的不同/唯一计数

excel - 从 Excel VBA 运行 Bat 文件

java - 兴趣点 Excel : get style name

python - 使用 Pandas 删除 Python 3.4.2 中的标题行

c# - 在 EPPlus 中调用 LoadFromCollection 时忽略属性

node.js - 如何将csv/xlsx文件上传到mongodb?

python - matplotlib: "TypeError: Image data can not convert to float"看起来像一个精细矩阵

python - 正则表达式Python单步,匹配包含两个以上分隔数字的仅文本括号

python - 如何在 python 中通过 udp (DTLS) 套接字实现 http/3 协议(protocol)?