我是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')
。 - Umar.Hopenpyxl
,命令为pip install openypyxl
。查看其他人遇到类似问题的解决方案,这似乎是一个很大的破坏性变化。 - Umar.H