w3resource

Pandas Series: pct_change() function

Percentage change between the current and a prior element

The pct_change() function is used to get 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.

Syntax:

Series.pct_change(self, periods=1, fill_method='pad', limit=None, freq=None, **kwargs)
Pandas Series pct_change image

Parameters:

Name Description Type/Default Value Required / Optional
periods Periods to shift for forming percent change. int
Default Value: 1
Required
fill_method How to handle NAs before computing percent changes. str
Default Value: ‘pad’
Required
limit The number of consecutive NAs to fill before stopping. int
Default Value: None
Required
freq Increment to use from time series API (e.g. ‘M’ or BDay()). DateOffset, timedelta, or offset alias string Optional
**kwargs Additional keyword arguments are passed into DataFrame.shift or Series.shift. Required

Returns: chg - Series or DataFrame
The same type as the calling object.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts