pyspark.pandas.Series.pct_change

Series.pct_change(periods: int = 1) → pyspark.pandas.series.Series

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 move all data into single partition in single machine and could cause serious performance degradation. Avoid this method against very large dataset.

Parameters
periodsint, default 1

Periods to shift for forming percent change.

Returns
Series

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