是猫猫子吖 2024-02-16 16:25 采纳率: 63.6%
浏览 439
已结题

原来能运行出来的,现在运行不出来了

这是我的代码

import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_excel(r'C:/Users/Lenovo/Desktop/数据.xlsx',index_col = 0) # 设置导入数据的路径
data.head()
print(data)
data.plot(figsize=(12,8))
plt.legend(bbox_to_anchor=(1.25,0.5))
plt.xlabel('Time')
plt.ylabel('Sales Volume')
plt.title('Monthly Sales Volume')
plt.show()


```这是一开始运行的结果

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/092232c6fdd74487a2c8f0018fe55cf6.png "#left")
后来不知道点到什么,运行不出来了,显示成这个了

C:\Users\Lenovo\PycharmProjects\pythonProject6\venv\Scripts\python.exe C:\Users\Lenovo\PycharmProjects\pythonProject6\main.py
C:\Users\Lenovo\PycharmProjects\pythonProject6\main.py:1: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466

import pandas as pd
Traceback (most recent call last):
File "C:\Users\Lenovo\PycharmProjects\pythonProject6\venv\Lib\site-packages\pandas\compat_optional.py", line 135, in import_optional_dependency
module = importlib.import_module(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python311\Lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1140, 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\Lenovo\PycharmProjects\pythonProject6\main.py", line 3, in
data = pd.read_excel(r'C:/Users/Lenovo/Desktop/数据.xlsx',index_col = 0) # 设置导入数据的路径
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lenovo\PycharmProjects\pythonProject6\venv\Lib\site-packages\pandas\io\excel_base.py", line 495, in read_excel
io = ExcelFile(
^^^^^^^^^^
File "C:\Users\Lenovo\PycharmProjects\pythonProject6\venv\Lib\site-packages\pandas\io\excel_

```

  • 写回答

3条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2024-02-16 16:26
    关注

    引自免费微信小程序:皆我百晓生

    您好!从您提供的错误信息来看,问题出在Python环境中缺少必要的库。具体来说:

    1. DeprecationWarning 提示:

      • Pandas 未来版本(3.0)将把 PyArrow 列为必需的依赖项以提供更高效的性能和与其他库更好的互操作性,但当前您的系统中未安装 PyArrow。您可以按照官方建议,在反馈的同时考虑安装 PyArrow 库来避免未来的兼容性问题。
        pip install pyarrow
        
    2. ModuleNotFoundError: No module named 'openpyxl' 错误:

      • 您尝试使用 pd.read_excel 函数读取 Excel 文件时,Pandas 需要 openpyxl 这个库来支持 .xlsx 格式的文件解析,但在您的环境中没有找到这个模块。解决这个问题,您需要安装 openpyxl:
        pip install openpyxl
        

    为了确保您的代码能正常运行,请首先安装这两个缺失的库:

    pip install pyarrow openpyxl
    

    然后重新运行您的原始代码:

    import pandas as pd
    import matplotlib.pyplot as plt
    
    data = pd.read_excel(r'C:/Users/Lenovo/Desktop/数据.xlsx', index_col=0) # 设置导入数据的路径
    data.head()
    print(data)
    data.plot(figsize=(12,8))
    plt.legend(bbox_to_anchor=(1.25,0.5))
    plt.xlabel('Time')
    plt.ylabel('Sales Volume')
    plt.title('Monthly Sales Volume')
    plt.show()
    

    这样应该就能正确地读取 Excel 数据并绘制图表了。如果还有其他问题,请继续提问。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月24日
  • 已采纳回答 2月16日
  • 创建了问题 2月16日