find monthly climatology for a particular month
ds = nc.groupby('time.month', squeeze = False).mean('time')


Here, you may put a "filter" either before or after group by.

Either you can do this-

df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
                          'foo', 'bar'],
                   'B' : [1, 2, 3, 4, 5, 6],
                   'C' : [2.0, 5., 8., 1., 2., 9.]})
grouped = df.groupby('A')
grouped.filter(lambda x: x['B'].mean() &gt; 3.)


Source - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.filter.html

Or something like this-

gdf.apply(lambda g: g[g['team'] == 'A']).reset_index(drop=True).groupby(gdf.grouper.names)


Source- https://stackoverflow.com/questions/27488080/python-pandas-filter-rows-after-groupby