From aea16787f0aa75dc129a3ba9c61fd8d883f31fc4 Mon Sep 17 00:00:00 2001 From: Matteo Raso Date: Thu, 6 Oct 2022 01:01:37 -0400 Subject: [PATCH 1/2] DOC: Fixed documentation for pivot_table margins (#48916) The documentation for the margins parameter of pivot_table was incorrect. It said that the parameter added rows and columns, but it actually passed them to aggfunc. I used the documentation from the user guide to replace the old documentation, as well as added a sentence to the documentation for aggfunc that explained its role in calculating margins. --- pandas/core/frame.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 597694dcd80af..704971b26dd93 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8604,12 +8604,15 @@ def pivot( hierarchical columns whose top level are the function names (inferred from the function objects themselves) If dict is passed, the key is column to aggregate and value - is function or list of functions. + is function or list of functions. If margin = ``True``, + aggfunc will be used to calculate the partial aggregates. fill_value : scalar, default None Value to replace missing values with (in the resulting pivot table, after aggregation). margins : bool, default False - Add all row / columns (e.g. for subtotal / grand totals). + If ``margins=True``, special ``All`` columns and rows + will be added with partial group aggregates across the categories + on the rows and columns. dropna : bool, default True Do not include columns whose entries are all NaN. If True, rows with a NaN value in any column will be omitted before From fc061d93302cc64162af3143d4aa60a78e0a2427 Mon Sep 17 00:00:00 2001 From: Matteo Raso <33975162+MatteoRaso@users.noreply.github.com> Date: Thu, 6 Oct 2022 14:57:47 -0400 Subject: [PATCH 2/2] Update pandas/core/frame.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 704971b26dd93..592b0f0ba62b8 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8604,7 +8604,7 @@ def pivot( hierarchical columns whose top level are the function names (inferred from the function objects themselves) If dict is passed, the key is column to aggregate and value - is function or list of functions. If margin = ``True``, + is function or list of functions. If ``margin=True``, aggfunc will be used to calculate the partial aggregates. fill_value : scalar, default None Value to replace missing values with (in the resulting pivot table,