【发布时间】:2018-12-16 20:40:24
【问题描述】:
我有一堆名为 None(空字符串)的工作表的 xlsx 文件
当我尝试使用pandas 读取文件时,xlrd 会引发list index out of range 错误。
Traceback (most recent call last):
File "/usr/local/bin/runxlrd.py", line 332, in main
ragged_rows=options.ragged_rows,
File "/Library/Python/2.7/site-packages/xlrd/__init__.py", line 416, in open_workbook
ragged_rows=ragged_rows,
File "/Library/Python/2.7/site-packages/xlrd/xlsx.py", line 791, in open_workbook_2007_xml
x12sheet.process_stream(zflo, heading)
File "/Library/Python/2.7/site-packages/xlrd/xlsx.py", line 528, in own_process_stream
self_do_row(elem)
File "/Library/Python/2.7/site-packages/xlrd/xlsx.py", line 667, in do_row
value = self.sst[int(tvalue)]
IndexError: list index out of range
我在xrld github 中发现了我认为相关的this 问题。
如果我更改工作表的名称,pandas 会成功读取文件。
我无法共享文件作为示例(隐私问题),当我尝试使用 None 作为工作表名称创建演示文件时,Excel 引发了无效名称错误。
包版本。
pkg_resources.get_distribution("xlrd").version
Out[3]: '1.1.0'
pd.__version__
Out[4]: '0.23.0'
有没有办法用 pandas 或可以更改工作表名称的脚本(任何语言)读取此文件?
【问题讨论】:
-
您的意思是您正在尝试使用
xlrd打开 Excel 电子表格吗?其中一张被称为无?我不确定xml文件在哪里使用。 -
对不起,我的错误,我的意思是
xlsx文件。 Pandas 使用 as xlrd 打开xlsx文件。