Series.
pct_change
Percentage change between the current and a prior element.
Note
the current implementation of this API uses Spark’s Window without specifying partition specification. This leads to moveing all data into a single partition in a single machine and could cause serious performance degradation. Avoid this method with very large datasets.
Periods to shift for forming percent change.
Examples
>>> psser = ps.Series([90, 91, 85], index=[2, 4, 1]) >>> psser 2 90 4 91 1 85 dtype: int64
>>> psser.pct_change() 2 NaN 4 0.011111 1 -0.065934 dtype: float64
>>> psser.sort_index().pct_change() 1 NaN 2 0.058824 4 0.011111 dtype: float64
>>> psser.pct_change(periods=2) 2 NaN 4 NaN 1 -0.055556 dtype: float64