-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: improved pivot_table(..) aggfunc parameter explanation #18718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4413,10 +4413,12 @@ def pivot(self, index=None, columns=None, values=None): | |
list can contain any of the other types (except list). | ||
Keys to group by on the pivot table column. If an array is passed, | ||
it is being used as the same manner as column values. | ||
aggfunc : function or list of functions, default numpy.mean | ||
aggfunc : function or list of functions or dict, default numpy.mean | ||
If list of functions passed, the resulting pivot table will have | ||
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 | ||
fill_value : scalar, default None | ||
Value to replace missing values with | ||
margins : boolean, default False | ||
|
@@ -4460,6 +4462,30 @@ def pivot(self, index=None, columns=None, values=None): | |
foo one 4.0 1.0 | ||
two NaN 6.0 | ||
|
||
>>> table = pivot_table(df, values='D', index=['A', 'B'], | ||
... columns=['C'], aggfunc=np.sum) | ||
>>> table | ||
... # doctest: +NORMALIZE_WHITESPACE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove this line (as we currently don't doctest our docstrings yet) |
||
C large small | ||
A B | ||
bar one 4.0 5.0 | ||
two 7.0 6.0 | ||
foo one 4.0 1.0 | ||
two NaN 6.0 | ||
|
||
>>> table = pivot_table(df, values=['D', 'E'], index=['A', 'C'], | ||
... aggfunc={'D': np.mean, | ||
... 'E': [min, max, np.mean]}) | ||
>>> table | ||
... # doctest: +NORMALIZE_WHITESPACE | ||
D E | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, done. |
||
mean max median min | ||
A C | ||
bar large 5.500000 16 14.5 13 | ||
small 5.500000 15 14.5 14 | ||
foo large 2.000000 10 9.5 9 | ||
small 2.333333 12 11.0 8 | ||
|
||
Returns | ||
------- | ||
table : DataFrame | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'function or list of ..' -> 'function, list of ...'