导入excel文件失败

问题描述 投票:0回答:0

我试图将 excel 文件导入 python,这是我的代码:

import pandas as pd

df = pd.read_excel('Sales.xlsx')

print(df)

不知何故,我得到了一个错误列表,但我不知道如何解决它

Traceback (most recent call last):
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\compat\_optional.py", line 141, in import_optional_dependency
    module = importlib.import_module(name)
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'openpyxl'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\wongs\OneDrive\Desktop\utar\y2s3\data mining\P2 TASK 3.py", line 3, in <module>
    df = pd.read_excel('Sales.xlsx')
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\excel\_base.py", line 482, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\excel\_base.py", line 1695, in __init__
    self._reader = self._engines[engine](self._io, storage_options=storage_options)
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\io\excel\_openpyxl.py", line 556, in __init__
    import_optional_dependency("openpyxl")
  File "C:\Users\wongs\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\compat\_optional.py", line 144, in import_optional_dependency
    raise ImportError(msg)
ImportError: Missing optional dependency 'openpyxl'.  Use pip or conda to install openpyxl.

请帮助我T_T

python excel pandas
© www.soinside.com 2019 - 2024. All rights reserved.