Home » excel » excel – Python pandas read_excel method KeyError 'show'

excel – Python pandas read_excel method KeyError 'show'

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to read an excel File, extension .xlsx, with Pandas and it is displaying a KeyError: 'show'

This is the full error stack trace:

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'

If I open and re-save the file, then it reads perfectly fine so I am thinking the problem is with some formatting or Excel versioning that pandas is unable to read.

In my app, I can’t ask the user to re-save so it needs to work right away. I have tested ~1000 files and there is only one that is giving this error.

What can I do to make sure the file is read when this error is thrown?

How to&Answers:

So the error you are having is happening because of an old error from xlrd.

The problem has been fixed in the Pull Request #323

Update the pandas package, the xlrd package and it should work again.