Skip to content

BUG: unstack(fill_value) does nothing when unstacking multiple columns #13971

Closed
@jzwinck

Description

@jzwinck

In #9746 we got a fill_value argument for pd.unstack(). But it does nothing if we unstack multiple levels at once:

df = pd.DataFrame({'x':['a', 'a', 'b'], 'y':['j', 'k', 'j'], 'z':[0, 1, 2], 'w':[0, 1, 2]})
df.set_index(['x', 'y', 'z']).unstack(['x', 'y'], fill_value=0)

That gives:

     w          
x    a         b
y    j    k    j
z               
0  0.0  NaN  NaN
1  NaN  1.0  NaN
2  NaN  NaN  2.0

It should give zeros instead of NaN.

Pandas 0.18.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Missing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions