filter groupby pandas

Solutions on MaxInterview for filter groupby pandas by the best coders in the world

showing results for - "filter groupby pandas"
Isabell
25 Apr 2018
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