Pandas-profiling: ValueError when generating profile from dataframe

Created on 17 Jul 2017  路  6Comments  路  Source: pandas-profiling/pandas-profiling

I have a pandas dataframe, when I try to generated report from df.head(), everything works fine. But when I try to generate report for the whole dataframe, I get this error:

ValueError                                Traceback (most recent call last)
<ipython-input-54-b5ad826014b5> in <module>()
----> 1 pandas_profiling.ProfileReport(df)

./python3.5/site-packages/pandas_profiling/__init__.py in __init__(self, df, **kwargs)
     15         sample = kwargs.get('sample', df.head())
     16 
---> 17         description_set = describe(df, **kwargs)
     18 
     19         self.html = to_html(sample,

./python3.5/site-packages/pandas_profiling/base.py in describe(df, bins, correlation_overrides, pool_size, **kwargs)
    307 
    308         confusion_matrix=pd.crosstab(data1,data2)
--> 309         if confusion_matrix.values.diagonal().sum() == len(df):
    310             ldesc[name1] = pd.Series(['RECODED', name2], index=['type', 'correlation_var'])
    311 

ValueError: diag requires an array of at least two dimensions
bug 馃悰

All 6 comments

Could you provide a dataset that I can reproduce this error?

Thanks

@conradoqg unfortunately I don't have it anymore. Context of this error has been lost.

I have the same error. Unfortunately I cannot provide the data set :(

I have been able to reproduce this error. And I can post data that reproduces it.

Describe the bug
Error output:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-d4e9ca79f757> in <module>()
----> 1 df3.profile_report()

/anaconda3/lib/python3.6/site-packages/pandas_profiling/controller/pandas_decorator.py in profile_report(df, **kwargs)
     14         A ProfileReport of the DataFrame.
     15     """
---> 16     p = ProfileReport(df, **kwargs)
     17     return p
     18 

/anaconda3/lib/python3.6/site-packages/pandas_profiling/__init__.py in __init__(self, df, **kwargs)
     56 
     57         # Get dataset statistics
---> 58         description_set = describe_df(df)
     59 
     60         # Get sample

/anaconda3/lib/python3.6/site-packages/pandas_profiling/model/describe.py in describe(df)
    454 
    455     # Get correlations
--> 456     correlations = calculate_correlations(df, variables)
    457 
    458     # Check correlations between numerical variables

/anaconda3/lib/python3.6/site-packages/pandas_profiling/model/correlations.py in calculate_correlations(df, variables)
    187     for correlation_name, get_matrix in categorical_correlations.items():
    188         if config["correlations"][correlation_name].get(bool):
--> 189             correlation = get_matrix(df, variables)
    190             if len(correlation) > 0:
    191                 correlations[correlation_name] = correlation

/anaconda3/lib/python3.6/site-packages/pandas_profiling/model/correlations.py in recoded_matrix(df, variables)
     72         A recoded matrix for categorical variables.
     73     """
---> 74     return categorical_matrix(df, variables, partial(check_recoded, count=len(df)))
     75 
     76 

/anaconda3/lib/python3.6/site-packages/pandas_profiling/model/correlations.py in categorical_matrix(df, variables, correlation_function)
    108         correlation_matrix.loc[name2, name1] = correlation_matrix.loc[
    109             name1, name2
--> 110         ] = correlation_function(confusion_matrix)
    111 
    112     return correlation_matrix

/anaconda3/lib/python3.6/site-packages/pandas_profiling/model/correlations.py in check_recoded(confusion_matrix, count)
     44         Whether the variables are recoded.
     45     """
---> 46     return int(confusion_matrix.values.diagonal().sum() == count)
     47 
     48 

ValueError: diag requires an array of at least two dimensions

To Reproduce

import pandas as pd
import pandas_profiling
import requests

response = requests.get(
    'https://raw.githubusercontent.com/adamrossnelson/HelloWorld/master/sparefiles/buggy1.pkl'
)
pkl_name = 'buggy1.pkl'
pkl_file = open(pkl_name, 'wb')
pkl_file.write(response.content)
pkl_file.close()

df = pd.read_pickle('buggy1.pkl')
df.profile_report()

Version information:
See my version output on previous issue:
https://github.com/pandas-profiling/pandas-profiling/issues/194

Additional context
No error when... If you save the df to a csv, then read from csv and then attempt a profile report.
Otherwise I would have just saved the example data as a csv. I was only able to reproduce when I pickled the data.

Would be happy to resubmit as a new issue if that would be helpful.

@adamrossnelson: The CSV conversion in your case effectively produces the same output as:

python df.replace('', np.nan, inplace=True) df.fillna(np.nan, inplace=True)
What were the values before converting the DataFrame to pickle? If the '' values are intentional, we will need a way for the package to work with them.

The use of None and '' are at least problematic, I'll have a look..

Should be resolved in v2.1.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shahanesanket picture shahanesanket  路  6Comments

iolap-mmeyyappan picture iolap-mmeyyappan  路  3Comments

castorfou picture castorfou  路  5Comments

aqzwy picture aqzwy  路  4Comments

romainx picture romainx  路  5Comments