ValueError when rendering html report using Pandas_profiling

Viewed 291

I am getting the following error when running a profile report for a subset of my DataFrame.

ValueError: Value '6.180529706513958' should be a ratio between 1 and 0.

This works:

profile = ProfileReport(
    df, title="Profile Report of the January Conversion Dataset"
)
profile.to_file(Path("../../../products/jan_cvr_report.html"))

profile0 = ProfileReport(
    df[df['conversion']==0], title="Profile Report of the January Conversion==0 Dataset"
)
profile0.to_file(Path("../../../products/jan_cvr0_report.html"))

This does not:

profile1 = ProfileReport(
    df[df['conversion']==1], title="Profile Report of the January Conversion==1 Dataset"
)
profile1.to_file(Path("../../../products/jan_cvr1_report.html"))
1 Answers

I found a closed Github issue that had a suggestion I got to work. My details and stack trace live there.

Solution: remove_unused_categories

df1 = df[df['conversion']==1].copy(deep=True)
df1.user_id.cat.remove_unused_categories(inplace=True)

After running the above, the profile report worked fine. The classes are extremely unbalanced so when subsetting to just where conversion=1 most of the user_ids are not used. This also fixable by not having the user_id as a category. However, this could be an issue with other categories so I am sharing anyway.

Related