Skip to content

fill_value kwarg for unstack #9746

Closed
Closed
@amcpherson

Description

@amcpherson

Currently:

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

In [3]: df.set_index(['x', 'y']).unstack()
Out[3]:
   z
y  j   k
x
a  0   1
b  2 NaN

If I want to fill with -1, i need to fillna and then astype back to int. Ideally:

In [3]: df.set_index(['x', 'y']).unstack(fill_value=-1)
Out[3]:
   z
y  j   k
x
a  0   1
b  2  -1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions