Skip to content

Commit d642261

Browse files
committed
DOC: include additional example for dataframe set_index method
1 parent 798f8e7 commit d642261

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pandas/core/frame.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,8 +2947,8 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
29472947
29482948
Examples
29492949
--------
2950-
>>> df = pd.DataFrame({'month': [1,4,7,10],
2951-
... 'year': [2012,2014,2013,2014],
2950+
>>> df = pd.DataFrame({'month': [1, 4, 7, 10],
2951+
... 'year': [2012, 2014, 2013, 2014],
29522952
... 'sale':[55, 40, 84, 31]})
29532953
month sale year
29542954
0 1 55 2012
@@ -2979,6 +2979,17 @@ def set_index(self, keys, drop=True, append=False, inplace=False,
29792979
2014 10 31
29802980
29812981
2982+
Create a multi-index using a set of values and a column:
2983+
2984+
>>> df.set_index([[1, 2, 3, 4], 'year'])
2985+
month sale
2986+
year
2987+
1 2012 1 55
2988+
2 2014 4 40
2989+
3 2013 7 84
2990+
4 2014 10 31
2991+
2992+
29822993
Returns
29832994
-------
29842995
dataframe : DataFrame

0 commit comments

Comments
 (0)