Skip to content

Commit 71c06b8

Browse files
committed
Merge pull request #9007 from SteveSimmons/fix-8944-cookbook-transform
Fix groupby().transform() example in cookbook.rst
2 parents 2e63fe2 + 6ce8e36 commit 71c06b8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

doc/source/cookbook.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
489489
.. ipython:: python
490490
491491
def GrowUp(x):
492-
avg_weight = sum(x[x.size == 'S'].weight * 1.5)
493-
avg_weight += sum(x[x.size == 'M'].weight * 1.25)
494-
avg_weight += sum(x[x.size == 'L'].weight)
495-
avg_weight = avg_weight / len(x)
492+
avg_weight = sum(x[x['size'] == 'S'].weight * 1.5)
493+
avg_weight += sum(x[x['size'] == 'M'].weight * 1.25)
494+
avg_weight += sum(x[x['size'] == 'L'].weight)
495+
avg_weight /= len(x)
496496
return pd.Series(['L',avg_weight,True], index=['size', 'weight', 'adult'])
497497
498498
expected_df = gb.apply(GrowUp)

0 commit comments

Comments
 (0)