Skip to content

Commit

Permalink
Subclassed pct_change for SeriesGroupBy
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Mar 8, 2018
1 parent db8ea80 commit 8f2074b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3901,6 +3901,13 @@ def _apply_to_column_groupbys(self, func):
""" return a pass thru """
return func(self)

def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None):
"""Calculate percent change of each value to previous entry in group"""
filled = getattr(self, fill_method)(limit=limit)
shifted = filled.shift(periods=periods, freq=freq)

return (filled / shifted) - 1


class NDFrameGroupBy(GroupBy):

Expand Down

0 comments on commit 8f2074b

Please sign in to comment.