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

Google Colab中使用ydata-profiling生成对比报告时遇AttributeError报错

在Google Colab中使用ydata-profiling生成数据集对比报告时出现AttributeError

问题详情

我在Google Colab里尝试用ydata-profiling(原pandas-profiling)生成原始数据集和缺失值填充后数据集的对比报告,按教程操作后仍报错。

我的代码

import pandas as pd
from pandas_profiling import ProfileReport

df = pd.read_csv("hcc.csv")
profile = ProfileReport(df,title="HCC Profile Report")
     
# 填充缺失值
df_transformed = df.copy()
from sklearn.impute import SimpleImputer
mean_imputer = SimpleImputer(strategy="mean")
df_transformed['Ferritin'] = mean_imputer.fit_transform(df_transformed['Ferritin'].values.reshape(-1,1))

transformed_profile = ProfileReport(df_transformed, title="Transformed Data")
comparison_report = profile.compare(transformed_profile)
comparison_report.to_file("original_vs_transformed.html")

报错信息

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-2068c7bbb3f6> in <module>
      1 transformed_profile = ProfileReport(df_transformed, title="Transformed Data")
      2 comparison_report = profile.compare(transformed_profile)
----> 3 comparison_report.to_file("original_vs_transformed.html")

16 frames
/usr/local/lib/python3.8/dist-packages/pandas_profiling/visualisation/plot.py in _plot_histogram(config, series, bins, figsize, date, hide_yaxis)
     74 
     75         if not hide_yaxis:
---&gt; 76             fig.supylabel("Frequency")
     77         else:
     78             fig = plt.figure(figsize=figsize)

AttributeError: 'Figure' object has no attribute 'supylabel'

错误提示:'Figure'对象没有'supylabel'属性

解决方案

这个问题源于Colab默认的Matplotlib版本过低——supylabel是Matplotlib 3.4.0及以上版本才新增的方法,旧版本Figure对象无此属性。

解决步骤:

  1. 升级Matplotlib到最新稳定版
  2. 重启Colab运行时(升级后需重新加载库)
  3. 重新运行分析代码

升级命令:

!pip install --upgrade matplotlib

重启运行时:点击Colab顶部菜单栏「Runtime」→「Restart runtime」

另外建议:pandas-profiling已更名为ydata-profiling,替换导入语句可避免后续版本兼容问题:

import pandas as pd
from ydata_profiling import ProfileReport

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 06:55:21