[PYTHON] "Import Error: Install xlrd> = 0.9.0 for Excel support" error in Pandas. Resolved by changing to use openpyxl

When I was trying the code to read the Excel file in the sample of "100 knocks of Python practice data", the following error occurred.

ImportError: Install xlrd >= 0.9.0 for Excel support

Solutions

Install openpyxl

pip install openpyxl

Specify engine in the parameter of read_excel () of pandas

#Before correction
# kokyaku_data = pd.read_excel("kokyaku_daicho.xlsx")

#Revised
kokyaku_data = pd.read_excel("kokyaku_daicho.xlsx", engine="openpyxl")

The default engine of Pandas is xlrd, but recently it has become non-compliant with xlsx files, so I was able to avoid the error by switching the engine to openpyxl.

xlrd will be fixed soon, but until then it seems better to deal with it above.

What I tried

For reference, make a note of what you tried after the error occurred.

I've done various things, but maybe I can only do the above ...

Try importing xlrd by referring to this article.

pip install xlrd

However, this time I got an error that the installed xlrd does not support xlsx files.

XLRDError: Excel xlsx file; not supported

In this article, you can find out that it was solved in Pandas 1.2.0.

Reference: Pandas 1.2.0 related articles

So uninstall Pandas once and install 1.2.0. As of 2021/1/6, it seemed to be 1.1.3 if the version was not specified, so specify the version and install.

pip install pandas==1.2.0

By the way, when I tried to install with conda, it failed. Also, numpy has been automatically updated to 1.19.5.

Then the following error

ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead.

What do you mean? When I looked it up,

--Install openpyxl --Specify engine as a parameter of read_excel () of pandas

It should be done.

pd.read_excel("sample.xlsx", engine="openpyxl")

Reference: https://teratail.com/questions/310586

Recommended Posts

"Import Error: Install xlrd> = 0.9.0 for Excel support" error in Pandas. Resolved by changing to use openpyxl
"Import Error: Install xlrd> = 0.9.0 for Excel support" error in Pandas. Resolved by changing to use openpyxl
Install python on xserver to use pip
Install tweepy with pip and use it for API 1.1
Error when trying to install psycopg2 in Python
Save pandas data in Excel format to data assets with Cloud Pak for Data (Watson Studio)