我正在尝试使用pd.read_excel读取几个excel文件。但是,存在错误:UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 114-115: unexpected end of data
。
所以我尝试添加encoding = "latin1"
,下面是错误:TypeError: read_excel() got an unexpected keyword argument 'encoding'
。
当我使用Excel将xls保存为csv,然后使用encoding="latin1"
读取csv时,它可以工作。但是,我想直接阅读xls,而不需要转换为csv。有可能解决这个问题吗?谢谢。
编辑:如果使用xlsx而不是xls,导入就能工作。
发布于 2020-10-08 16:11:34
这是熊猫的变化 1.1.0。编码不再是read_excel()
的参数。
read_excel()不再使用**kwds参数。这意味着传入关键字参数chunksize现在会引发TypeError (以前引发NotImplementedError),而传入关键字参数编码现在会引发TypeError (GH34464)。
您可以尝试以下几种方法:
wb = xlrd.open_workbook(path, encoding_override='latin1')
df = pd.read_excel(wb)
https://stackoverflow.com/questions/64272068
复制