BUG: Fix pivot_table margins to include NaN groups when dropna=False #61524
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix incorrect margin computation in
pivot_table
when index or columns contain NA valuesThis PR fixes an issue where the
"All"
row or column (i.e.,margins=True
) inpd.pivot_table
does not account for rows that containNA
values 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
NA
values are included in the aggregation, consistent with how the data is treated in the main table whendropna=False
.doc/source/whatsnew/v3.0.0.rst
underReshaping