Pandas read_excel 在升级xlrd 2.0.1之后不支持xlsx的应对方法
Pandas1.2.2已经处理掉这个问题啦,直接更新就对了~
==================================
下面就不用看啦~
由于xlrd 2.0.1升级后,官文这样解释
xlrd is a library for reading data and formatting information from Excel files in the historical
.xls
format. #只能够操作xls老版本文件,如何操作xlsx需要调用其他的库
官文 #官文:有介绍如果需要操作xlsx有很多种方法,如下


我们在使用pandas read_excel的时候默认engine=xlrd,以前是可以通吃xlsx,和xls的文件,
在更新为2.0.1之后,如果不指定engine='openpyxl’的话默认xlrd只能读取xls文件
import pandas as pd
df=pd.read_excel(r'C:\Users\Administrator\Desktop\1.xlsx') #默认engine=xlrd
print(df)
engine : str, default None
If io is not a buffer or path, this must be set to identify io.
Supported engines: "xlrd", "openpyxl", "odf", "pyxlsb", default "xlrd".
Engine compatibility :
- "xlrd" supports most old/new Excel file formats.
- "openpyxl" supports newer Excel file formats.
- "odf" supports OpenDocument file formats (.odf, .ods, .odt).
- "pyxlsb" supports Binary Excel files.
#需要读xlsx文件 需要制定engine='openpyxl'
df=pd.read_excel(r'C:\Users\Administrator\Desktop\1.xlsx',engine='openpyxl')
当用pandas read_excel指定openpyxl批量读取文件的时候又会遇到
“UserWarning:Workbook contains no default style”
这样的报错
本人想要指定engine=pylightxl或者其他可以编辑xlsx的库的时候发现read_excel的engine是不支持的.
…
因此在pandas下次更新之前, 个人还是把xlrd退到了1.2.0的版本
cmd下
- pip uninstall xlrd
- pip install xlrd==1.2.0
就OK啦