用pandas读xlsx文件时报错:
/usr/python3/lib/python3.8/site-packages/xlrd/__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)
168 # files that xlrd can parse don't start with the expected signature.
169 if file_format and file_format != 'xls':
--> 170 raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
171
172 bk = open_workbook_xls(
XLRDError: Excel xlsx file; not supported
这是由于新版本的xlrd只支持xls文件
解决办法:
- 安装旧版本xlrd
>>> pip3 install xlrd==1.2.0
- 使用openpyxl代替xlrd
>>> pip3 install openpyxl
# 指定engine为openpyxl
>>> pd.read_excel('xxxx.xlsx', engine='openpyxl')