Skip to content

Commit eb49283

Browse files
monicaBeejreback
monicaBee
authored andcommitted
DOC: Added filtering example to groupby doc
Filtering example for dataframe with > 2 fields -- filtering collapses to dataframe, not series.
1 parent a57d59d commit eb49283

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/source/groupby.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ with NaNs.
571571
572572
dff.groupby('B').filter(lambda x: len(x) > 2, dropna=False)
573573
574+
For dataframes with multiple columns, filters should explicitly specify a column as the filter criterion.
575+
576+
.. ipython:: python
577+
578+
dff['C'] = np.arange(8)
579+
dff.groupby('B').filter(lambda x: len(x['C']) > 2)
580+
574581
.. _groupby.dispatch:
575582

576583
Dispatching to instance methods
@@ -650,7 +657,7 @@ The dimension of the returned result can also change:
650657
.. ipython:: python
651658
652659
def f(x):
653-
return Series([ x, x**2 ], index = ['x', 'x^s'])
660+
return Series([ x, x**2 ], index = ['x', 'x^s'])
654661
s = Series(np.random.rand(5))
655662
s
656663
s.apply(f)

0 commit comments

Comments
 (0)