Skip to content

Commit 8f2074b

Browse files
committed
Subclassed pct_change for SeriesGroupBy
1 parent db8ea80 commit 8f2074b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/groupby.py

+7
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,13 @@ def _apply_to_column_groupbys(self, func):
39013901
""" return a pass thru """
39023902
return func(self)
39033903

3904+
def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None):
3905+
"""Calculate percent change of each value to previous entry in group"""
3906+
filled = getattr(self, fill_method)(limit=limit)
3907+
shifted = filled.shift(periods=periods, freq=freq)
3908+
3909+
return (filled / shifted) - 1
3910+
39043911

39053912
class NDFrameGroupBy(GroupBy):
39063913

0 commit comments

Comments
 (0)