Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame([
    [2, 3, 4, 5],
    [6, 7, 8, 9],
    [10, 11, 12, 13]
]).set_index([0, 1]).rename_axis(['p', 'q'])
In [3]:
df.columns = pd.MultiIndex.from_tuples([
   ('r', 't'), ('s', 'v')
], names=['l_1', 'l_2'])

df
Out[3]:
l_1 r s
l_2 t v
p q
2 3 4 5
6 7 8 9
10 11 12 13
In [4]:
df.droplevel('p')
Out[4]:
l_1 r s
l_2 t v
q
3 4 5
7 8 9
11 12 13
In [5]:
df.droplevel('l_2', axis=1)
Out[5]:
l_1 r s
p q
2 3 4 5
6 7 8 9
10 11 12 13