2

df.profile_report() fails immediately after installation using import pandas_profiling

The package is installed properly, because I can generate a report in Jupyter by importing and using just the constructor ProfileReport(df). However, the syntax df.profile_report() does not work.

When I run df.profile_report() I get an error message below:

```AttributeError Traceback (most recent call last)
in 
----> 1 df.profile_report()

C:\Anaconda3\envs\quantecon\lib\site-packages\pandas\core\generic.py in getattr(self, name)
5065 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5066 return self[name]
-> 5067 return object.getattribute(self, name)
5068
5069 def setattr(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'profile_report'
```

Version information:

  • Python 3.7.1

  • pandas==0.24.2

  • Windows 10 2022H2

    import pandas as pd
    from pandas_profiling import ProfileReport
    
    # The dataframe is the same as the tutorial example given by the author.  
    
    df = pd.DataFrame(np.random.rand(100, 5), columns=['a', 'b', 'c', 'd', 'e'])    
    
    df.profile_report() # this fails.```
    
    

What else I've tried that does work is as follows: from pandas_profiling import ProfileReport ...steps to create dataframe df ProfileReport(df)

Using the constructor ProfileReport(df) by itself at least gets me a report in my Jupyter Notebook. Because of this I know the package is installed and working. However, the object.method() route to get the report doesn't work. But many other methods rely on the object.method() syntax.

I cannot get any dataframes work with the df.profile_report() method.

```import numpy as np
import pandas as pd
from pandas_profiling import ProfileReport

# The dataframe is the same as the tutorial example given by the author.  

df = pd.DataFrame(
    np.random.rand(100, 5),
    columns=['a', 'b', 'c', 'd', 'e']
)    

df.profile_report() # this fails.
ProfileReport(df)  # this works, but `df.profile_report()` does not work.
```

My guess as to what's wrong...?

Since the pandas error is referring to "generic.py" for Pandas Core DataFrame, and the error is "no attribute 'profile_report', perhaps it is the decorator that wraps the dataframe object and modifies it to give it the extra attribute method of .profile_report() ?? That is my guess. I don't know what's causing the error, since it works when I "peek under the covers" and use the report constructor directly. I just cannot use the other methods that rely on the object.method() syntax.

Rich Lysakowski PhD
  • 2,702
  • 31
  • 44
  • did you try using `import pandas_profiling` instead of `from pandas_profiling import ProfileReport`? – D_Serg Jun 29 '19 at 16:49
  • Yes, I followed the instructions first. When I run : `import pandas_profiling df.profile_report()` ... I get the message : `AttributeError Traceback (most recent call last) in -> 1 df.profile_report() C:\ ... site-packages\pandas\core\generic.py in __getattr__(self, name) -> 5067 return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute 'profile_report' ( I had to delete some characters to be under the 500 character comment limit. ) – Rich Lysakowski PhD Jul 01 '19 at 01:22
  • I am sorry but you did not read my question correctly. I tried exactly what is suggested in the github repository for installation and usage, and what you suggest, but it does not work. I will try it in a different virtual environment to see if I can isolate the problem to my Python package set. I am getting a Pandas error, not pandas_profiling error. "AttributeError: 'DataFrame' object has no attribute 'profile_report' " See above for the original error. – Rich Lysakowski PhD Jul 11 '19 at 22:33

3 Answers3

0

The .profile_report() syntax was introduced in pandas_profiling version 2.

You can install this version via pip: pip install pandas-profiling.

EDIT

The way to import the package is:

import pandas_profiling

in contrast to your current approach

from pandas_profiling import ProfileReport

Simon
  • 5,464
  • 6
  • 49
  • 85
0

This will work for google colab

!pip uninstall -y pandas-profiling

!pip install -U pandas-profiling
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • Thanks for the suggestion, and yet I need to run it locally, not on a cloud platform. What pandas_profiling and pandas versions are you running? – Rich Lysakowski PhD Nov 16 '22 at 00:32
-1

Try this:

import pandas_profiling

pandas_profiling.describe_df(data_df)
html_str_output = pandas_profiling.ProfileReport(data_df)
  • This alternative worked for me (where the df.profile_report() did not ... but used to). In a notebook, you can display the report inline with this: `pandas_profiling.ProfileReport(df)` Or output to an HTML file: `html_str_output = pandas_profiling.ProfileReport(df)` `html_str_output.to_file('test_output.htm)` – Joseph True Nov 22 '19 at 20:39