In [1]:
import pandas as pd
In [2]:
classes = ["class 1"] * 5 + ["class 2"] * 5
sub_class = ['c1','c2','c2','c1','c3'] + ['c1','c2','c3','c2','c3']
vals = [1,3,5,1,3] + [2,6,7,5,2]
p_df = pd.DataFrame({"class": classes, "sub_class": sub_class, "vals": vals})
In [3]:
p_df
Out[3]:
In [4]:
grouped = p_df.groupby(['class', 'sub_class'])['vals'].median()
In [5]:
grouped
Out[5]:
In [6]:
for index_val, value in grouped.iteritems():
class_name, sub_class_name = index_val
print(class_name, ":", sub_class_name, ":", value)
In [ ]: