fill_value kwarg for unstack · Issue #9746 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
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