You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add all row / columns (e.g. for subtotal / grand totals).
From what I can see, margins=True will return row and column means, not sums, at least if no aggfunc is specified. If there's a way to get sums, not means, I don't know what it is. Here's an example showing margins=True returning row and column means, not sums:
print(sales.pivot_table(values="weekly_sales", index="department", columns="type", fill_value=0, margins=True))
type A B All
department
1 30961.725 44050.627 32052.467
2 67600.159 112958.527 71380.023
... ... ... ...
98 12875.423 217.428 11820.590
99 379.124 0.000 379.124
All 23674.667 25696.678 23843.950
Suggested fix for documentation
I don't know the fix for sure, because I don't know if margins=True behaves differently when an aggfunc is specified. But if it returns the mean rather than the sum, I suggest:
Provide the mean value for each row and each column.
The text was updated successfully, but these errors were encountered:
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.
* 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.
* Update pandas/core/frame.py
Co-authored-by: Matthew Roeschke <[email protected]>
Co-authored-by: Matthew Roeschke <[email protected]>
…andas-dev#48965)
* DOC: Fixed documentation for pivot_table margins (pandas-dev#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.
* Update pandas/core/frame.py
Co-authored-by: Matthew Roeschke <[email protected]>
Co-authored-by: Matthew Roeschke <[email protected]>
Pandas version checks
main
hereLocation of the documentation
https://pandas.pydata.org/docs/reference/api/pandas.pivot_table.html
Documentation problem
The documentation for the
margins
parameter says:From what I can see,
margins=True
will return row and column means, not sums, at least if noaggfunc
is specified. If there's a way to get sums, not means, I don't know what it is. Here's an example showingmargins=True
returning row and column means, not sums:Suggested fix for documentation
I don't know the fix for sure, because I don't know if
margins=True
behaves differently when anaggfunc
is specified. But if it returns the mean rather than the sum, I suggest:The text was updated successfully, but these errors were encountered: