BUG: Fix pivot_table margins to include NaN groups when dropna=False#61524
BUG: Fix pivot_table margins to include NaN groups when dropna=False#61524rhshadrach merged 3 commits intopandas-dev:mainfrom
Conversation
|
This change fixes the margin behavior in Before I go ahead and update those tests to match the new behavior, I just wanted to double-check if this is the direction we want to take, treating |
|
@iabhi4 - thanks for putting this up. The crosstab failures here look like bugs to me as well. E.g. in the penultimate column
|
|
@rhshadrach Thanks for confirming! I’ve updated the test cases to reflect the corrected behavior |
|
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
rhshadrach
left a comment
There was a problem hiding this comment.
Looks good, just a small request.
43db0bd to
9891c6d
Compare
|
Thanks @iabhi4! |
Fix incorrect margin computation in
pivot_tablewhen index or columns contain NA valuesThis PR fixes an issue where the
"All"row or column (i.e.,margins=True) inpd.pivot_tabledoes not account for rows that containNAvalues in the index or column dimensions. These rows were incorrectly excluded from the overall aggregation used to compute the margin, leading to incorrect totals.The fix modifies the margin calculation to ensure that rows with
NAvalues are included in the aggregation, consistent with how the data is treated in the main table whendropna=False.doc/source/whatsnew/v3.0.0.rstunderReshaping