def filter(self, func, dropna=True, *args, **kwargs):  
if isinstance(func, str):<EOL><INDENT>wrapper = lambda x: getattr(x, func)(*args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>wrapper = lambda x: func(x, *args, **kwargs)<EOL><DEDENT>def true_and_notna(x, *args, **kwargs):<EOL><INDENT>b = wrapper(x, *args, **kwargs)<EOL>return b and notna(b)<EOL><DEDENT>try:<EOL><INDENT>indices = [self._get_index(name) for name, group in self<EOL>if true_and_notna(group)]<EOL><DEDENT>except ValueError:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>except TypeError:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>filtered = self._apply_filter(indices, dropna)<EOL>return filtered<EOL>
Return a copy of a Series excluding elements from groups that
do not satisfy the boolean criterion specified by func.

Parameters
----------
func : function
    To apply to each group. Should return True or False.
dropna : Drop groups that do not pass the filter. True by default;
    if False, groups that evaluate False are filled with NaNs.

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')
>>> df.groupby('A').B.filter(lambda x: x.mean() > 3.)
1    2
3    4
5    6
Name: B, dtype: int64

Returns
-------
filtered : Series