fill_value kwarg for unstack (original) (raw)

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