def maxu():
    r = df.groupby('a').apply(lambda x: x.b.mean() if len(x) >= 5 else -1)
return r[r > 0]

def maxu2():
    return df.groupby('a').apply(lambda x: x.b.mean() if len(x) >= 5 else -1
        ).to_frame().rename(columns={(0): 'mean'}).query('mean > 0')

def alexander():
    return df.groupby('a', as_index=False).filter(lambda group: group.a.
        count() >= 5).groupby('a').mean()

def alexander2():
    vc = df.a.value_counts()
return df.loc[df.a.isin(vc[vc >= 5].index)].groupby('a').mean()
Chaining grouping, filtration and aggregation