mito icon indicating copy to clipboard operation
mito copied to clipboard

Pivot tables should return 0 instead of NaN on count, count unique, and sum aggreatations

Open aarondr77 opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. When creating a pivot table with a count aggregation, instead of returning 0 if there are no records that fall into a specific group, Mito returns NaN. Returning NaN values is reasonable for other types of aggregation types (ie: mean), but not for count.

Describe the solution you'd like I'd like Mito to automatically convert NaN values to 0 when that is clearly the expected behavior in pivot tables. This should occur when the aggregation type is count, count unique, or sum.

It can be accomplished using the code aggfunc='count', fill_value=0,

Describe alternatives you've considered Alternatively, I can use the pandas fillnan(0) function. However, this takes me out of Mito, which breaks up my analysis across multiple Mitosheets for no good reason.

aarondr77 avatar Jan 25 '22 16:01 aarondr77

This is seconded by another user via Discord who said that he usually sets a fill value of 0 so that his pivot table is not populated with NaN values.

aarondr77 avatar Jan 27 '22 17:01 aarondr77

Sweet. For count, count unique, and sum this makes a lot of sense.

Can you specify how this would work with multiple aggregations? E.g. what if you aggregate with a sum but also a median.

Seems like the ideal case is we can set the fill_value for count, count unique, and sum, but not for the other ones. Is this doable?

naterush avatar Jan 27 '22 17:01 naterush

Unfortunately, the fill_value takes a single value. So we can't specify 0 for some while other remain NaN.

aarondr77 avatar Apr 21 '22 18:04 aarondr77