In [2]:
import pandas as pd
import io
In [4]:
data = io.StringIO('''Fruit,Color,Count,Price
Apple,Red,3,$1.29
Apple,Green,9,$0.99
Pear,Red,25,$2.59
Pear,Green,26,$2.79
Lime,Green,99,$0.39
''')
df_unindexed = pd.read_csv(data)
df_unindexed
Out[4]:
In [5]:
df = df_unindexed.set_index(['Fruit', 'Color'])
df
Out[5]:
In [6]:
df.xs('Apple')
Out[6]: