LoginSignup
24
15

More than 3 years have passed since last update.

pandasでExcelファイル(xlsx)が読み込めない時の対処法

Last updated at Posted at 2020-12-22

環境について

pandas== 1.1.4
xlrd==2.0.1

エラーについて

pandasでExcelファイル(xlsx)を読み込む時に

import pandas as pd

df = pd.read_excel('sample.xlsx')

下記のエラーが発生する.

xlrd.biffh.XLRDError: Excel xlsx file; not supported

原因

Excelファイルを読み取るライブラリであるxlrdが2.0.0からxlsxファイルに対応しなくなったため.
https://xlrd.readthedocs.io/en/latest/changes.html

解決方法

2つの解決方法があります.

1.xlrdのバージョンを下げる

pip3 install xlrd==1.2.0

2.ファイルを読み取るライブラリをopenpyxlに変更する

pipでopenpyxlをインストールする.

pip3 install openpyxl

Excel読み取り時にライブラリを指定する.

df = pd.read_excel('sample.xlsx',engine="openpyxl")
24
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
15