From 1168273efa0f941eae734645dc2d3d82ae778016 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 17 Sep 2018 20:48:23 -0500 Subject: [PATCH] FutureWarning from groupby. Warning about elementwise comparison failing when we indexed a dataframe with boolean dataframe --- doc/source/cookbook.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/source/cookbook.rst b/doc/source/cookbook.rst index f6fa9e9f86143..a4dc99383a562 100644 --- a/doc/source/cookbook.rst +++ b/doc/source/cookbook.rst @@ -505,13 +505,11 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to .. ipython:: python df = pd.DataFrame({'A' : [1, 1, 2, 2], 'B' : [1, -1, 1, 2]}) - gb = df.groupby('A') def replace(g): - mask = g < 0 - g.loc[mask] = g[~mask].mean() - return g + mask = g < 0 + return g.where(mask, g[~mask].mean()) gb.transform(replace)