Examples
import numpy as np
import pandas as pd
d = {'num_legs': [4, 4, 2, 2],
'num_wings': [0, 0, 2, 2],
'class': ['mammal', 'mammal', 'bird', 'bird'],
'animal': ['tiger', 'fox', 'penguin', 'sparrow'],
'locomotion': ['walks', 'walks', 'walks', 'flies']}
df = pd.DataFrame(data=d)
df = df.set_index(['class', 'animal', 'locomotion'])
df
Get values at specified index
df.xs('mammal')
Get values at several indexes:
df.xs(('mammal', 'fox'))
Get values at specified index and level:
df.xs('tiger', level=1)
Get values at several indexes and levels
df.xs(('bird', 'walks'),
level=[0, 'locomotion'])
Get values at specified column and axis:
df.xs('num_wings', axis=1)