【问题标题】:Pandas-profiling error AttributeError: 'DataFrame' object has no attribute 'profile_report'Pandas 分析错误 AttributeError:“DataFrame”对象没有属性“profile_report”
【发布时间】:2019-12-03 05:16:37
【问题描述】:

我想使用 pandas-profiling 对数据集执行一些 eda,但出现错误:AttributeError: 'DataFrame' object has no attribute 'profile_report'

我在 spyder 上创建了一个 python 脚本,代码如下:

import pandas as pd import pandas_profiling data_abc = pd.read_csv('abc.csv') profile = data_abc.profile_report(title='Pandas Profiling Report') profile.to_file(output_file="abc_pandas_profiling.html")

AttributeError: 'DataFrame' 对象没有属性 'profile_report'

【问题讨论】:

标签: python-3.x pandas pandas-profiling


【解决方案1】:

df.profile_report() 入口点从 v2.0.0 开始可用。 soln from here

您是否通过 pip 或 conda 安装了 pandas-profiling?

使用:pip install -U pandas-profiling 来解决这个问题并重启你的内核

【讨论】:

    【解决方案2】:

    问题在于团队尚未更新 pip 或 conda 安装(描述为 here)。如果您使用其中一种安装,请暂时尝试此方法。

    profile = pandas_profiling.ProfileReport(df)
    print(profile)
    

    【讨论】:

      【解决方案3】:

      对于那些使用 google colabs 的人,分析库已经过时,因此使用下面的命令并重新启动运行时

      ! pip install https://github.com/pandas-profiling/pandas-profiling/archive/master.zip 
      

      【讨论】:

        【解决方案4】:

        这应该适用于那些想要使用最新版本的人:

        1. 在 anaconda 提示符下运行 pip uninstall pandas_profiling(假设您使用的是 Spyder,我猜这就是您的情况)/或命令提示符
        2. 运行pip install https://github.com/pandas-profiling/pandas-profiling/archive/master.zip

        如果您使用的是 Jupyter Notebook/Jupyter Lab 之类的东西,请务必重新启动内核并重新导入包。

        我希望这会有所帮助。

        【讨论】:

        • 我刚刚使用这个命令卸载了我用 Anaconda3 安装的包,并启动了 pip install pandas_profiling:我得到了最新版本 2.8.0 并且正在运行 - Thx
        【解决方案5】:

        我发现的唯一解决方法是我制作的 python 脚本是从命令提示符处执行并给出正确的输出,但代码在 Spyder 中仍然给出错误。

        【讨论】:

          【解决方案6】:

          在conda环境中试试

          !pip install --user pandas-profiling
          import pandas_profiling
          data.profile_report()
          

          【讨论】:

            【解决方案7】:

            pandas-profiling 的某些版本不适合我,我安装了 2.8.0 版本,它适合我。

            !pip install pandas-profiling==2.8.0
            import numpy as np
            import pandas as pd
            import pandas_profiling as pp
            df = pd.read_csv('/content/sample_data/california_housing_train.csv')
            profile = df.profile_report(title = "Data Profiling Report")
            profile.to_file("ProfileReportTest.html")
            

            【讨论】:

              【解决方案8】:

              如果以上都不起作用,您可以通过在 read_csv 中将编码设置为 unicode_escape 来检查吗?这可能是由于您的某一列

               encoding = 'unicode_escape'
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2017-02-12
                • 2014-01-10
                • 2019-07-03
                • 1970-01-01
                • 1970-01-01
                • 2013-04-28
                • 1970-01-01
                • 2013-10-23
                相关资源
                最近更新 更多