zenn.skin 무료버전 배포중!
자세히보기

Python/Syntax

read_excel로 xlsx 파일 열기

koosco! 2021. 11. 21. 23:03

pandas 라이브러리의 read_excel을 이용해 xlsx파일을 읽으려하면 지원하지 않는다며 오류가 발생한다.

 

df = pd.read_excel('data/회원정보.xlsx', sheet_name='Sheet1')
print(df)

 

xlrd는 파이썬에서 엑셀 파일을 불러올 수 있도록 도와주는 라이브러리인데

xlrd2부터 xls파일 이외의 파일은 지원하지 않는다고 한다.

pandas는 엑셀파일을 읽을 때 기존과 동일하게 xlrd를 기본엔진으로 사용하고 있어 지원하지 않는다고 뜨는 것이다.

 

engine을 xlrd이외의 라이브러리로 변경해주면 정상적으로 xlsx파일을 읽을 수 있다.

 

df = pd.read_excel('data/회원정보.xlsx', sheet_name='Sheet1', engine='openpyxl')
print(df)

 

 


아래는 정식으로 xlrd에서 xls 이외의 파일을 지원하지 않겠다는 내용의 글

 

xlrd 2 released

On 16 Jan 2021, at 16:05, Chris Withers wrote: > xlsx files are made up of a zip file wrapping an xml file. > > Both xml and zip have well documented security issues, which xlrd was > not doing a good job of handling. In particular, it appeared that > defu

groups.google.com

 

'Python/Syntax'의 다른글

  • 현재글 read_excel로 xlsx 파일 열기

관련글