-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the DataFrame.pivot docstring #20250
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
75cb343
0d1efb8
e880c47
3dbafa1
b13cbd0
fb80f04
d454a30
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 |
---|---|---|
|
@@ -4341,27 +4341,31 @@ def last_valid_index(self): | |
|
||
def pivot(self, index=None, columns=None, values=None): | ||
""" | ||
Return reshaped DataFrame summarized by given index / column values. | ||
|
||
Reshape data (produce a "pivot" table) based on column values. Uses | ||
unique values from index / columns to form axes of the resulting | ||
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. can you add single backtick around index and column ? (to reference them as parameters). I would maybe also say "from specified index / columns" to make it clear it is not the existing index / columns |
||
DataFrame. | ||
DataFrame. This function does not support data aggregation, multiple | ||
values will result in hierarchically indexed columns. | ||
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. in multiindexed columns. |
||
|
||
Parameters | ||
---------- | ||
index : string or object, optional | ||
Column name to use to make new frame's index. If None, uses | ||
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. Would it be clearer to just say "Column" instead of "Column name". I know the value you specify is the name, but what you actually use to make the new frame's index is the actual column, not the column name ... |
||
existing index. | ||
columns : string or object | ||
Column name to use to make new frame's columns | ||
columns : string or object, optional | ||
Column name to use to make new frame's columns. | ||
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. What happens in this case if you do not specify it? |
||
values : string or object, optional | ||
Column name to use for populating new frame's values. If not | ||
specified, all remaining columns will be used and the result will | ||
have hierarchically indexed columns | ||
have hierarchically indexed columns. | ||
|
||
Returns | ||
------- | ||
pivoted : DataFrame | ||
DataFrame | ||
Returns reshaped DataFrame. | ||
|
||
See also | ||
See Also | ||
-------- | ||
DataFrame.pivot_table : generalization of pivot that can handle | ||
duplicate values for one index/column pair | ||
|
@@ -4377,8 +4381,8 @@ def pivot(self, index=None, columns=None, values=None): | |
-------- | ||
|
||
>>> df = pd.DataFrame({'foo': ['one','one','one','two','two','two'], | ||
'bar': ['A', 'B', 'C', 'A', 'B', 'C'], | ||
'baz': [1, 2, 3, 4, 5, 6]}) | ||
... 'bar': ['A', 'B', 'C', 'A', 'B', 'C'], | ||
... 'baz': [1, 2, 3, 4, 5, 6]}) | ||
>>> df | ||
foo bar baz | ||
0 one A 1 | ||
|
@@ -4389,16 +4393,16 @@ def pivot(self, index=None, columns=None, values=None): | |
5 two C 6 | ||
|
||
>>> df.pivot(index='foo', columns='bar', values='baz') | ||
A B C | ||
bar A B C | ||
foo | ||
one 1 2 3 | ||
two 4 5 6 | ||
|
||
>>> df.pivot(index='foo', columns='bar')['baz'] | ||
A B C | ||
bar A B C | ||
foo | ||
one 1 2 3 | ||
two 4 5 6 | ||
|
||
|
||
""" | ||
from pandas.core.reshape.reshape import pivot | ||
return pivot(self, index=index, columns=columns, values=values) | ||
|
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.
I think "summarized" is misleading here, as there is no "summary" (aggregation) calculation happening.
(I don't directly have the "better" wording in mind though. And the "reshaping" is important, as you already mention)