为了能够读取 xlsb 文件,必须安装 openpyxl。
根据https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html#pandas.read_excel
引擎:str,默认无
如果 io 不是缓冲区或路径,则必须将其设置为标识 io。支持的引擎:“xlrd”、“openpyxl”、“odf”、“pyxlsb”。引擎兼容性:
“xlrd”支持旧式 Excel 文件 (.xls)。
“openpyxl”支持更新的 Excel 文件格式。
“odf”支持 OpenDocument 文件格式(.odf、.ods、.odt)。
“pyxlsb”支持二进制 Excel 文件。
在 1.2.0 版中更改:引擎 xlrd 现在仅支持旧式 .xls 文件。
当engine=None时,将使用以下逻辑来判断引擎:
如果 path_or_buffer 是 OpenDocument 格式(.odf、.ods、.odt),则将使用 odf。
否则如果path_or_buffer是xls格式,就会使用xlrd。
否则如果安装了openpyxl,则使用openpyxl。
否则,如果安装了 xlrd >= 2.0,则会引发 ValueError。
否则将使用 xlrd 并引发 FutureWarning。这种情况会在未来版本的 pandas 中引发 ValueError。
没有 index_col 的 xlsb 读取:
import pandas as pd
dfcluster = pd.read_excel('c:/xml/baseline/distribucion.xlsb', sheet_name='Cluster', index_col=0, engine='pyxlsb')