我正在尝试使用Pandas读取扩展名为.xlsx的excel文件,并且显示KeyError: 'show'
这是完整的错误堆栈跟踪:
File "~/Python_VirtualEnv/api/lib/python3.7/site-packages/pandas/io/excel.py", line 653, in __init__
self._reader = self._engines[engine](self._io)
File "~/Python_VirtualEnv/api/lib/python3.7/site-packages/pandas/io/excel.py", line 424, in __init__
self.book = xlrd.open_workbook(filepath_or_buffer)
File "~/Python_VirtualEnv/api/lib/python3.7/site-packages/xlrd/__init__.py", line 138, in open_workbook
ragged_rows=ragged_rows,
File "~/Python_VirtualEnv/api/lib/python3.7/site-packages/xlrd/xlsx.py", line 812, in open_workbook_2007_xml
x12book.process_stream(zflo, 'Workbook')
File "~/Python_VirtualEnv/api/lib/python3.7/site-packages/xlrd/xlsx.py", line 271, in process_stream
meth(self, elem)
File "~/Python_VirtualEnv/api/lib/python3.7/site-packages/xlrd/xlsx.py", line 397, in do_sheet
bk._sheet_visibility.append(visibility_map[state])
KeyError: 'show'
如果我打开并重新保存文件,那么它读起来就很好,所以我认为问题出在熊猫无法读取的某些格式或Excel版本中。
在我的应用中,我无法要求用户重新保存,因此需要立即进行操作。我已经测试了大约1000个文件,只有一个文件出现此错误。
当抛出此错误时,我该怎么做才能确保读取文件?
答案 0 :(得分:1)