Python: Pandas read_excel 无法打开 .xls 文件,不支持 xlrd
Python: Pandas read_excel cannot open .xls file, xlrd not supported
问题:
我正在用 pd.read_excel 打开 .xls,但出现错误。 (“打包 excel 文件” 从 https://cima.aemps.es/cima/publico/nomenclator.html 下载)
df_cima = pd.read_excel("price_tracker/es/support/Presentaciones.xls")
xlrd.biffh.XLRDError: Excel xlsx file; not supported
这个文件的后缀是.xls 但是这个错误告诉我它是.xlsx
然后我尝试添加engine="openpyxl"
,当xlrd版本不再是1.2.0时,它通常用于读取.xlsx,然后它又给我一个错误
openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.
我的环境:
- pandas版本:1.1.5
- xlrd 版本:2.0.1
- openpyxl 版本:3.0.6
我不想将我的 xlrd 版本更改回 1.2.0,从其他答案我看到新版本的 xlrd 仅支持 .xls,但我不支持了解为什么它不适用于我的文件。
提前致谢。
你的文件不是.xls,我坚持! :)
With Pandas 1.1.5 and xlrd 2.1.0
将 Presentaciones.xls
重命名为 Presentaciones.xlsx
。
import pandas as pd
# Use openpyxl.
df = pd.read_excel(r'X:...\Presentaciones.xlsx', engine='openpyxl')
print(df)
尽情享受吧! :)
更多信息
我怎么知道你的文件是假的 .xls
和非常真实的 .xlsx
?
因为 openpyxl
不适用于 xls
个文件。
import pandas as pd
df = pd.read_excel(r'X:...\test.xls', engine='openpyxl')
/*
ERROR:
InvalidFileException: openpyxl does not support the old .xls file format,
please use xlrd to read this file, or convert it to the more recent .xlsx file format.
*/
并且尝试简单地将 test.xls
重命名为 test.xlsx
也不起作用!
import pandas as pd
df = pd.read_excel(r'X:...\test.xlsx', engine='openpyxl')
/*
Error:
OSError: File contains no valid workbook part
*/
历史
注意,.xlsx
扩展名(由 pandas 检测到)意味着此文件中可能有脚本。有时扩展名可能会说谎,所以小心!
panda 停止支持 xlsx
文件的原因是 这些文件存在安全隐患 并且没有人维护这部分代码。
问题:
我正在用 pd.read_excel 打开 .xls,但出现错误。 (“打包 excel 文件” 从 https://cima.aemps.es/cima/publico/nomenclator.html 下载)
df_cima = pd.read_excel("price_tracker/es/support/Presentaciones.xls")
xlrd.biffh.XLRDError: Excel xlsx file; not supported
这个文件的后缀是.xls 但是这个错误告诉我它是.xlsx
然后我尝试添加engine="openpyxl"
,当xlrd版本不再是1.2.0时,它通常用于读取.xlsx,然后它又给我一个错误
openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.
我的环境:
- pandas版本:1.1.5
- xlrd 版本:2.0.1
- openpyxl 版本:3.0.6
我不想将我的 xlrd 版本更改回 1.2.0,从其他答案我看到新版本的 xlrd 仅支持 .xls,但我不支持了解为什么它不适用于我的文件。
提前致谢。
你的文件不是.xls,我坚持! :)
With Pandas 1.1.5 and xlrd 2.1.0
将 Presentaciones.xls
重命名为 Presentaciones.xlsx
。
import pandas as pd
# Use openpyxl.
df = pd.read_excel(r'X:...\Presentaciones.xlsx', engine='openpyxl')
print(df)
尽情享受吧! :)
更多信息
我怎么知道你的文件是假的 .xls
和非常真实的 .xlsx
?
因为 openpyxl
不适用于 xls
个文件。
import pandas as pd
df = pd.read_excel(r'X:...\test.xls', engine='openpyxl')
/*
ERROR:
InvalidFileException: openpyxl does not support the old .xls file format,
please use xlrd to read this file, or convert it to the more recent .xlsx file format.
*/
并且尝试简单地将 test.xls
重命名为 test.xlsx
也不起作用!
import pandas as pd
df = pd.read_excel(r'X:...\test.xlsx', engine='openpyxl')
/*
Error:
OSError: File contains no valid workbook part
*/
历史
注意,.xlsx
扩展名(由 pandas 检测到)意味着此文件中可能有脚本。有时扩展名可能会说谎,所以小心!
panda 停止支持 xlsx
文件的原因是 这些文件存在安全隐患 并且没有人维护这部分代码。