You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复“AttributeError: module 'pandas' has no attribute 'plotting'”错误?

Pandas无plotting属性的AttributeError解决方法

问题背景

在执行Kaggle「Hello Seaborn」教程的初始化代码时,触发AttributeError: module 'pandas' has no attribute 'plotting'错误。

执行代码

import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")

错误栈

AttributeError                            Traceback (most recent call last)
Cell In[21], line 2
      1 import pandas as pd
----> 2 pd.plotting.register_matplotlib_converters()
      3 import matplotlib.pyplot as plt
      4 get_ipython().run_line_magic('matplotlib', 'inline')

AttributeError: module 'pandas' has no attribute 'plotting'

当前环境信息

  • pandas 2.0.3
  • matplotlib 3.7.2
  • conda 23.5.0
  • Python 3.10.9

已尝试操作:卸载重装plotting包、更新pandas/matplotlib、升级Anaconda和Python版本,问题未解决。


解决方案

1. 排查本地同名文件冲突

当前工作目录若存在pandas.py或pandas.pyc文件,会覆盖官方pandas库的导入。执行以下代码验证导入路径:

import pandas as pd
print(pd.__file__)

若输出不是Anaconda或Python全局site-packages下的pandas路径,删除本地的pandas.py和pandas.pyc文件后重新运行代码。

2. 显式导入plotting模块

尝试直接导入register_matplotlib_converters函数,跳过pd.plotting的属性访问:

import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")

3. 修复pandas安装异常

若conda安装的pandas存在损坏,先卸载再用pip重装:

conda remove --yes pandas
pip install pandas==2.0.3

4. 纠正错误操作

不存在单独的plotting库,你之前卸载重装的「plotting」是无关包,无需单独安装——pandas.plotting是pandas内置模块,随pandas本体安装。


内容的提问来源于stack exchange,提问作者pot98tin67

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 08:17:13