一个人如何在熊猫中打开以下文件?
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'