Skip to content

Commit aff20eb

Browse files
DOC: correct DataFrame.pivot docstring (#14430)
The mention of panels that are created is not correct. You get a multi-index
1 parent 83a380c commit aff20eb

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

pandas/core/frame.py

+30-18
Original file line numberDiff line numberDiff line change
@@ -3868,9 +3868,8 @@ def last_valid_index(self):
38683868
def pivot(self, index=None, columns=None, values=None):
38693869
"""
38703870
Reshape data (produce a "pivot" table) based on column values. Uses
3871-
unique values from index / columns to form axes and return either
3872-
DataFrame or Panel, depending on whether you request a single value
3873-
column (DataFrame) or all columns (Panel)
3871+
unique values from index / columns to form axes of the resulting
3872+
DataFrame.
38743873
38753874
Parameters
38763875
----------
@@ -3880,7 +3879,20 @@ def pivot(self, index=None, columns=None, values=None):
38803879
columns : string or object
38813880
Column name to use to make new frame's columns
38823881
values : string or object, optional
3883-
Column name to use for populating new frame's values
3882+
Column name to use for populating new frame's values. If not
3883+
specified, all remaining columns will be used and the result will
3884+
have hierarchically indexed columns
3885+
3886+
Returns
3887+
-------
3888+
pivoted : DataFrame
3889+
3890+
See also
3891+
--------
3892+
DataFrame.pivot_table : generalization of pivot that can handle
3893+
duplicate values for one index/column pair
3894+
DataFrame.unstack : pivot based on the index values instead of a
3895+
column
38843896
38853897
Notes
38863898
-----
@@ -3889,30 +3901,30 @@ def pivot(self, index=None, columns=None, values=None):
38893901
38903902
Examples
38913903
--------
3904+
3905+
>>> df = pd.DataFrame({'foo': ['one','one','one','two','two','two'],
3906+
'bar': ['A', 'B', 'C', 'A', 'B', 'C'],
3907+
'baz': [1, 2, 3, 4, 5, 6]})
38923908
>>> df
38933909
foo bar baz
3894-
0 one A 1.
3895-
1 one B 2.
3896-
2 one C 3.
3897-
3 two A 4.
3898-
4 two B 5.
3899-
5 two C 6.
3900-
3901-
>>> df.pivot('foo', 'bar', 'baz')
3910+
0 one A 1
3911+
1 one B 2
3912+
2 one C 3
3913+
3 two A 4
3914+
4 two B 5
3915+
5 two C 6
3916+
3917+
>>> df.pivot(index='foo', columns='bar', values='baz')
39023918
A B C
39033919
one 1 2 3
39043920
two 4 5 6
39053921
3906-
>>> df.pivot('foo', 'bar')['baz']
3922+
>>> df.pivot(index='foo', columns='bar')['baz']
39073923
A B C
39083924
one 1 2 3
39093925
two 4 5 6
39103926
3911-
Returns
3912-
-------
3913-
pivoted : DataFrame
3914-
If no values column specified, will have hierarchically indexed
3915-
columns
3927+
39163928
"""
39173929
from pandas.core.reshape import pivot
39183930
return pivot(self, index=index, columns=columns, values=values)

0 commit comments

Comments
 (0)