解决pandas报错:XLRDError: Excel xlsx file; not supported

用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文件
解决办法:

  1. 安装旧版本xlrd
>>> pip3 install xlrd==1.2.0
  1. 使用openpyxl代替xlrd
>>> pip3 install openpyxl
# 指定engine为openpyxl
>>> pd.read_excel('xxxx.xlsx', engine='openpyxl')

参考:https://stackoverflow.com/a/65266270

你可能感兴趣的:(Python,数据处理,Pandas,python,pandas,xlsx,xlrd,openpyxl)