I have a DataFrame with index (a, b)
df = pd.DataFrame({'a' : [1, 2, 3, 1], 'b' : [11, 11, 11, -7], 'val' : [10, 19, 24, 12]})
df.set_index(['a', 'b'], inplace=True)
a | b | val
1 | 11 | 10
2 | 11 | 19
3 | 11 | 24
1 | -7 | 12
I'd like to pick from it only the rows with b == 11.
I've tried
df[df.index[1] == 11]
KeyError: False
It failed. Could you help?
xs. Please check:df.xs(11, level=1)locto keep the second level.