【发布时间】:2021-03-25 23:44:03
【问题描述】:
我是 Python 新手,遇到了问题。 我正在尝试使用 pandas 导入一个 excel 文件,并且我正在使用 VS Code。
import pandas as pd
data = pd.read_excel(r'D:\Python\user.xlsx')
print(data)
我已经安装了xlrd,但是我得到了这个错误:
Traceback (most recent call last):
File "d:\Python\import-excel.py", line 24, in <module>
data = pd.read_excel(r'D:\Python\user.xlsx')
File "D:\Python\venv\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "D:\Python\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 37, in load_workbook
return open_workbook(filepath_or_buffer)
File "D:\Python\venv\lib\site-packages\xlrd\__init__.py", line 170, in open_workbook
raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported
有人可以帮帮我吗?
【问题讨论】:
-
尝试更改引擎参数
pd.read_excel(r'D:\Python\user.xlsx',engine='openpyxl') -
谢谢@Manakin,但已经完成并收到另一个错误:ValueError: Unknown engine:
init_.py'> -
你可能需要先安装
openpyxlpip install openypyxl看看其他人有这个问题的骗局,似乎是一个很大的突破性变化 -
啊啊啊我看到了。我写了 engine=openpyxl 而不是 engine = 'openpyxl' :-))) 也没有 ''。谢谢
标签: python excel pandas visual-studio-code