Skip to content

Commit 1bfb70f

Browse files
adamkleinwesm
authored andcommitted
DOC: added stack/unstack docstrings per #531
Conflicts: pandas/core/frame.py
1 parent 2aa3b29 commit 1bfb70f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

pandas/core/frame.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -2395,17 +2395,35 @@ def pivot(self, index=None, columns=None, values=None):
23952395

23962396
def stack(self, level=-1, dropna=True):
23972397
"""
2398-
Convert DataFrame to Series with multi-level Index. Columns become the
2399-
second level of the resulting hierarchical index
2398+
Pivot a level of the (possibly hierarchical) column labels, returning a
2399+
DataFrame (or Series in the case of an object with a single level of
2400+
column labels) having a hierarchical index with a new inner-most level
2401+
of row labels.
24002402
24012403
Parameters
24022404
----------
24032405
level : int, string, or list of these, default last level
24042406
Level(s) to stack, can pass level name
2407+
dropna : boolean, default True
2408+
Whether to drop rows in the resulting Frame/Series with no valid
2409+
values
2410+
2411+
Examples
2412+
----------
2413+
>>> s
2414+
a b
2415+
one 1. 2.
2416+
two 3. 4.
2417+
2418+
>>> s.stack()
2419+
one a 1
2420+
b 2
2421+
two a 3
2422+
b 4
24052423
24062424
Returns
24072425
-------
2408-
stacked : Series
2426+
stacked : DataFrame or Series
24092427
"""
24102428
from pandas.core.reshape import stack
24112429

@@ -2419,14 +2437,17 @@ def stack(self, level=-1, dropna=True):
24192437

24202438
def unstack(self, level=-1):
24212439
"""
2440+
Pivot a level of the (necessarily hierarchical) index labels, returning
2441+
a DataFrame having a new level of column labels whose inner-most level
2442+
consists of the pivoted index labels.
24222443
"Unstack" level from MultiLevel index to produce reshaped DataFrame. If
24232444
the index is not a MultiIndex, the output will be a Series (the
24242445
analogue of stack when the columns are not a MultiIndex)
24252446
24262447
Parameters
24272448
----------
24282449
level : int, string, or list of these, default last level
2429-
Level(s) to unstack, can pass level name
2450+
Level(s) of index to unstack, can pass level name
24302451
24312452
Examples
24322453
--------

0 commit comments

Comments
 (0)