pby.SeriesGroupBy.rolling ](pandas.core.groupby.SeriesGroupBy.rolling.html)
    * [ pandas.core.groupby.SeriesGroupBy.sample ](pandas.core.groupby.SeriesGroupBy.sample.html)
    * [ pandas.core.groupby.SeriesGroupBy.sem ](pandas.core.groupby.SeriesGroupBy.sem.html)
    * [ pandas.core.groupby.SeriesGroupBy.shift ](pandas.core.groupby.SeriesGroupBy.shift.html)
    * [ pandas.core.groupby.SeriesGroupBy.size ](pandas.core.groupby.SeriesGroupBy.size.html)
    * [ pandas.core.groupby.SeriesGroupBy.skew ](pandas.core.groupby.SeriesGroupBy.skew.html)
    * [ pandas.core.groupby.SeriesGroupBy.std ](pandas.core.groupby.SeriesGroupBy.std.html)
    * [ pandas.core.groupby.SeriesGroupBy.sum ](pandas.core.groupby.SeriesGroupBy.sum.html)
    * [ pandas.core.groupby.SeriesGroupBy.var ](pandas.core.groupby.SeriesGroupBy.var.html)
    * [ pandas.core.groupby.SeriesGroupBy.tail ](pandas.core.groupby.SeriesGroupBy.tail.html)
    * [ pandas.core.groupby.SeriesGroupBy.take ](pandas.core.groupby.SeriesGroupBy.take.html)
    * [ pandas.core.groupby.SeriesGroupBy.value_counts ](pandas.core.groupby.SeriesGroupBy.value_counts.html)
    * [ pandas.core.groupby.DataFrameGroupBy.boxplot ](pandas.core.groupby.DataFrameGroupBy.boxplot.html)
    * [ pandas.core.groupby.DataFrameGroupBy.hist ](pandas.core.groupby.DataFrameGroupBy.hist.html)
    * [ pandas.core.groupby.SeriesGroupBy.hist ](pandas.core.groupby.SeriesGroupBy.hist.html)
    * [ pandas.core.groupby.DataFrameGroupBy.plot ](pandas.core.groupby.DataFrameGroupBy.plot.html)
    * [ pandas.core.groupby.SeriesGroupBy.plot ](pandas.core.groupby.SeriesGroupBy.plot.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ GroupBy ](../groupby.html)
  * pandas.core.... 

#  pandas.core.groupby.DataFrameGroupBy.filter  #

DataFrameGroupBy.  filter  (  _ func  _ , _ dropna  =  True  _ , _ *  args  _
, _ **  kwargs  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/groupby/generic.py#L1868-L1937) #

    

Filter elements from groups that donât satisfy a criterion.

Elements from groups are filtered if they do not satisfy the boolean criterion
specified by func.

Parameters  :

    

**func** function

    

Criterion to apply to each group. Should return True or False.

**dropna** bool

    

Drop groups that do not pass the filter. True by default; if False, groups
that evaluate False are filled with NaNs.

Returns  :

    

DataFrame

    

Notes

Each subframe is endowed the attribute ânameâ in case you need to know
which group you are working on.

Functions that mutate the passed object can produce unexpected behavior or
errors and are not supported. See [ Mutating with User Defined Function (UDF)
methods  ](../../user_guide/gotchas.html#gotchas-udf-mutation) for more
details.

Examples

    
    
    >>> 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() > 3.)
         A  B    C
    1  bar  2  5.0
    3  bar  4  1.0
    5  bar  6  9.0
    

[ __ previous  pandas.core.groupby.DataFrameGroupBy.pipe
](pandas.core.groupby.DataFrameGroupBy.pipe.html "previous page") [ next
pandas.core.groupby.SeriesGroupBy.filter  __
](pandas.core.groupby.SeriesGroupBy.filter.html "next page")

__ On this page

  * ` DataFrameGroupBy.filter()  `

[ __ Show Source
](../../_sources/reference/api/pandas.core.groupby.DataFrameGroupBy.filter.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created us