polars.Series.pct_change
-
Computes percentage change between values.
Percentage change (as fraction) between current element and most-recent non-null element at least
nperiod(s) before the current element.Computes the change from the previous row by default.
- Parameters:
-
- n
-
periods to shift for forming percent change.
Notes
Null values are preserved. If you’re coming from pandas, this matches their
fill_method=Nonebehaviour.Examples
>>> pl.Series(range(10)).pct_change() shape: (10,) Series: '' [f64] [ null inf 1.0 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 ]>>> pl.Series([1, 2, 4, 8, 16, 32, 64, 128, 256, 512]).pct_change(2) shape: (10,) Series: '' [f64] [ null null 3.0 3.0 3.0 3.0 3.0 3.0 3.0 3.0 ]
Series.pct_change(
n: int | IntoExprColumn = 1,
) → Series
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/series/api/polars.Series.pct_change.html