pandas.Series.pct_change¶
Percentage change between the current and a prior element.
Computes the percentage change from the immediately previous row by default. This is useful in comparing the percentage of change in a time series of elements.
- param periods
- int, default 1
Periods to shift for forming percent change.
- param fill_method
- str, default ‘pad’
How to handle NAs before computing percent changes.
- param limit
- int, default None
The number of consecutive NAs to fill before stopping.
- param freq
- DateOffset, timedelta, or offset alias string, optional
Increment to use from time series API (e.g. ‘M’ or BDay()). **kwargs Additional keyword arguments are passed into DataFrame.shift or Series.shift.
- return
chg : Series or DataFrame The same type as the calling object.
Limitations¶
Parameters limit, freq are currently unsupported by Intel Scalable Dataframe Compiler
- This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff
between staying in JIT-region with that function or going back to interpreter mode.
Examples¶
import numpy as np
import pandas as pd
from numba import njit
@njit
def series_pct_change():
s = pd.Series([5., 0, 3.3, np.nan, 9.2])
return s.pct_change(periods=2, fill_method=None, limit=None, freq=None)
print(series_pct_change())
$ python ./series/series_pct_change.py
0 NaN
1 NaN
2 -0.340000
3 NaN
4 1.787879
dtype: float64
See also
- Series.diff
Compute the difference of two elements in a Series.
- DataFrame.diff
Compute the difference of two elements in a DataFrame.
- Series.shift
Shift the index by some number of periods.
- DataFrame.shift
Shift the index by some number of periods.