BUG: pd.crosstab(dropna=True, values=) drops rows and columns where any aggregation result is null. #60767
Open
2 of 3 tasks
Labels
Bug
Needs Discussion
Requires discussion from core team before further action
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
When I provide
dropna=True
tocrosstab
and specify avalues
array to aggregate, pandas seems to drop rows and columns where all the results areNaN
. In this case pandasskew
givesNaN
if there are fewer than 3 values in a group, so only the value forindex=2, column=4
has a non-NaN
value. That leaves a row ofNaN
and a column ofNaN
, so pandas drops both the all-NaN
row and the all-NaN
column.Expected Behavior
The documentation says that
dropna=True
means, "Do not include columns whose entries are all NaN." I expect pandas to follow that rule and to keep values where the aggregation result isNaN
. In the example above, I expect to see 2 rows for the 2 possible values of A, 1 and 2, an 2 columns for the 2 possible values of B, 3 and 4.Installed Versions
The text was updated successfully, but these errors were encountered: