使用Pandas read_excel读取XLS文件时出错

时间:2020-11-10 23:33:28

标签: excel pandas

一个人如何在熊猫中打开以下文件?

https://results.enr.clarityelections.com/CA/Santa_Clara/106043/270668/reports/detailxls.zip

该zip文件包含一个xls文件:detail.xls,看起来像是带有BOM表字节的XML格式。

使用pd.read_excel打开xls文件时,出现以下错误:

>>> df = pd.read_excel('detail.xls')
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\xef\xbb\xbf<?xml'

>>> with open('detail.xls') as f:
        df = pd.read_excel(f)
TypeError: unsupported operand type(s) for <<: 'str' and 'int'

删除BOM字节后,pd.read_excel会引发以下错误:

>>> df = pd.read_excel('detail-nobom.xls')
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'<?xml ve'

>>> with open('detail-nobom.xls') as f:
        df = pd.read_excel(f)
TypeError: unsupported operand type(s) for <<: 'str' and 'int'

0 个答案:

没有答案