본문 바로가기

Python

[Python] pandas read_exel에서 .xlsx 파일이 안 열릴 때

문제인식 : Pandas에서 read_exel를 이용해서 xlsx 확장자의 파일을 열려고 할 때, 다음과 같은 오류가 발생할 때가 있다.

XLRDError: Excel xlsx file; not supported

문제 해결 : openpyxl 라이브러리를 설치하여 read_exel 옵션에서 engine을 openpyxl로 설정한다.

1. openpyxl 라이브러리를 설치한다.

pip install openpyxl

2. pandas 버전 1.0.1 이상을 사용 중인지 확인한다.

import pandas as pd
print(pd.__version__)

3. pandas로 .xlsx 파일을 읽을 때 openpyxl을 지정한다.

import pandas
df = pandas.read_excel(`<name-of-file>.xlsx`, engine=`openpyxl`)