snowflake.snowpark.modin.plugin.extensions.groupby_overrides.DataFrameGroupBy.pct_change¶

DataFrameGroupBy.pct_change(periods=1, fill_method=_NoDefault.no_default, limit=_NoDefault.no_default, freq=_NoDefault.no_default, axis=_NoDefault.no_default, **kwargs)[source]¶

Calculate pct_change of each value to previous entry in group.

Parameters:
  • periods (int, default 1) – Periods to shift for forming percent change.

  • fill_method ({"bfill", "ffill", "pad"}, default "ffill") –

    How to handle NAs before computing percent changes.

    Deprecated since version 2.1.0: All options of fill_method are deprecated except fill_method=None.

  • limit (int, optional) –

    The number of consecutive NAs to fill before stopping. Snowpark pandas does not yet support this parameter.

    Deprecated since version 2.1.0.

  • freq (DateOffset, timedelta, or str, optional) – Increment to use from time series API (e.g. ‘ME’ or BDay()). Snowpark pandas does not yet support this parameter.

Returns:

Percentage changes within each group.

Return type:

Series or DataFrame

Notes

This function ignores the as_index, sort, group_keys, and dropna arguments passed to the initial groupby call.

Examples

For SeriesGroupBy:

>>> lst = ['a', 'a', 'b', 'b']
>>> ser = pd.Series([1, 2, 3, 4], index=lst)
>>> ser
a    1
a    2
b    3
b    4
dtype: int64
>>> ser.groupby(level=0).pct_change()
a         NaN
a    1.000000
b         NaN
b    0.333333
dtype: float64
Copy

For DataFrameGroupBy:

>>> data = [[1, 2, 3], [1, 5, 6], [2, 5, 8], [2, 6, 9]]
>>> df = pd.DataFrame(data, columns=["a", "b", "c"], index=["tuna", "salmon", "catfish", "goldfish"])
>>> df  
           a  b  c
    tuna   1  2  3
  salmon   1  5  6
 catfish   2  5  8
goldfish   2  6  9
>>> df.groupby("a").pct_change()  
            b  c
    tuna    NaN    NaN
  salmon    1.5  1.000
 catfish    NaN    NaN
goldfish    0.2  0.125
Copy