w3resource

Pandas DataFrame: pct_change() function

DataFrame - pct_change() function

The pct_change() function returns 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:

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

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 Pandas DataFrame Notebooks from here.

Previous: DataFrame - mode() function
Next: DataFrame - prod() function



Follow us on Facebook and Twitter for latest update.