I would like to group the top results for each item in the index at level 0. For example, using this data / series block:
import pandas as pd
import numpy as np
np.random.seed(1)
index = list(zip(['A']*5 + ['B']*5, list(range(10))))
df = pd.Series(np.random.random((10)),
index=pd.MultiIndex.from_tuples(index, names=['i0', 'i1']),
name='val')
pd.DataFrame(df)

I would like to keep Aboth Bgrouped and return the top 3 val(decreasing) from each.
source
share