Stolen from stack overflow.
https://stackoverflow.com/questions/10175068/select-data-at-a-particular-level-from-a-multiindex
In [ ]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
print(pd.__version__)
import random
In [ ]:
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
s = pd.DataFrame({'RowCount':0}, index=index)
In [ ]:
s['RowCount'] = s.apply(axis=1, func=lambda row: random.randint(100,1000))
In [ ]:
s
In [ ]:
s.query("second == 'two'")
In [ ]: