Skip to content

Commit 1168273

Browse files
committed
FutureWarning from groupby.
Warning about elementwise comparison failing when we indexed a dataframe with boolean dataframe
1 parent 79f7762 commit 1168273

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

doc/source/cookbook.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,11 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
505505
.. ipython:: python
506506
507507
df = pd.DataFrame({'A' : [1, 1, 2, 2], 'B' : [1, -1, 1, 2]})
508-
509508
gb = df.groupby('A')
510509
511510
def replace(g):
512-
mask = g < 0
513-
g.loc[mask] = g[~mask].mean()
514-
return g
511+
mask = g < 0
512+
return g.where(mask, g[~mask].mean())
515513
516514
gb.transform(replace)
517515

0 commit comments

Comments
 (0)