@@ -2395,17 +2395,35 @@ def pivot(self, index=None, columns=None, values=None):
2395
2395
2396
2396
def stack (self , level = - 1 , dropna = True ):
2397
2397
"""
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.
2400
2402
2401
2403
Parameters
2402
2404
----------
2403
2405
level : int, string, or list of these, default last level
2404
2406
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
2405
2423
2406
2424
Returns
2407
2425
-------
2408
- stacked : Series
2426
+ stacked : DataFrame or Series
2409
2427
"""
2410
2428
from pandas .core .reshape import stack
2411
2429
@@ -2419,14 +2437,17 @@ def stack(self, level=-1, dropna=True):
2419
2437
2420
2438
def unstack (self , level = - 1 ):
2421
2439
"""
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.
2422
2443
"Unstack" level from MultiLevel index to produce reshaped DataFrame. If
2423
2444
the index is not a MultiIndex, the output will be a Series (the
2424
2445
analogue of stack when the columns are not a MultiIndex)
2425
2446
2426
2447
Parameters
2427
2448
----------
2428
2449
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
2430
2451
2431
2452
Examples
2432
2453
--------
0 commit comments