groupby where only

Solutions on MaxInterview for groupby where only by the best coders in the world

showing results for - "groupby where only"
Niko
05 Jun 2020
1>>> df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
2...                           'foo', 'bar'],
3...                    'B' : [1, 2, 3, 4, 5, 6],
4...                    'C' : [2.0, 5., 8., 1., 2., 9.]})
5>>> grouped = df.groupby('A')
6>>> grouped.filter(lambda x: x['B'].mean() > 3.)
7     A  B    C
81  bar  2  5.0
93  bar  4  1.0
105  bar  6  9.0
11