Skip to content

Commit 98a4a93

Browse files
Clarify filling behaviour with missing values
1 parent 77c9fac commit 98a4a93

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pandas/core/frame.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5225,8 +5225,8 @@ def stack(self, level=-1, dropna=True):
52255225
52265226
It is common to have missing values when stacking a dataframe
52275227
with multi-level columns, as the stacked dataframe typically
5228-
has more values than the original dataframe. By default the
5229-
missing values are filled with NaNs:
5228+
has more values than the original dataframe. Missing values
5229+
are filled with NaNs:
52305230
52315231
>>> df_multi_level_cols2
52325232
X Y
@@ -5240,13 +5240,19 @@ def stack(self, level=-1, dropna=True):
52405240
two a 2.0 NaN
52415241
b NaN 3.0
52425242
5243-
Multiple levels can be stacked at once
5244-
5245-
>>> df_multi_level_cols2.stack([1, 0])
5246-
one a X 0.0
5247-
b Y 1.0
5248-
two a X 2.0
5249-
b Y 3.0
5243+
The first parameter controls which level or levels are stacked:
5244+
5245+
>>> df_multi_level_cols2.stack(0)
5246+
a b
5247+
one X 0.0 NaN
5248+
Y NaN 1.0
5249+
two X 2.0 NaN
5250+
Y NaN 3.0
5251+
>>> df_multi_level_cols2.stack([0, 1])
5252+
one X a 0.0
5253+
Y b 1.0
5254+
two X a 2.0
5255+
Y b 3.0
52505256
dtype: float64
52515257
52525258
Note that rows where all values are missing are dropped by

0 commit comments

Comments
 (0)