@@ -3868,9 +3868,8 @@ def last_valid_index(self):
3868
3868
def pivot (self , index = None , columns = None , values = None ):
3869
3869
"""
3870
3870
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.
3874
3873
3875
3874
Parameters
3876
3875
----------
@@ -3880,7 +3879,20 @@ def pivot(self, index=None, columns=None, values=None):
3880
3879
columns : string or object
3881
3880
Column name to use to make new frame's columns
3882
3881
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
3884
3896
3885
3897
Notes
3886
3898
-----
@@ -3889,30 +3901,30 @@ def pivot(self, index=None, columns=None, values=None):
3889
3901
3890
3902
Examples
3891
3903
--------
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]})
3892
3908
>>> df
3893
3909
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')
3902
3918
A B C
3903
3919
one 1 2 3
3904
3920
two 4 5 6
3905
3921
3906
- >>> df.pivot('foo', 'bar')['baz']
3922
+ >>> df.pivot(index= 'foo', columns= 'bar')['baz']
3907
3923
A B C
3908
3924
one 1 2 3
3909
3925
two 4 5 6
3910
3926
3911
- Returns
3912
- -------
3913
- pivoted : DataFrame
3914
- If no values column specified, will have hierarchically indexed
3915
- columns
3927
+
3916
3928
"""
3917
3929
from pandas .core .reshape import pivot
3918
3930
return pivot (self , index = index , columns = columns , values = values )
0 commit comments