Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
index = pd.MultiIndex.from_tuples([('one', 'x'), ('one', 'y'),
                                   ('two', 'x'), ('two', 'y')])
s = pd.Series(np.arange(2.0, 6.0), index=index)
s
Out[2]:
one  x    2.0
     y    3.0
two  x    4.0
     y    5.0
dtype: float64

Pandas: Dataframe - unstack.

In [3]:
s.unstack(level=-1)
Out[3]:
x y
one 2.0 3.0
two 4.0 5.0

Pandas: Dataframe - unstack level=-1.

In [4]:
s.unstack(level=0)
Out[4]:
one two
x 2.0 4.0
y 3.0 5.0

Pandas: Dataframe - unstack level=0.

In [5]:
df = s.unstack(level=0)
df.unstack()
Out[5]:
one  x    2.0
     y    3.0
two  x    4.0
     y    5.0
dtype: float64