Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame pct_change() Method

❮ DataFrame Reference


Find the percentage difference between the values in current row and previous row:

import pandas as pd

data = [[10, 18, 11], [20, 15, 8], [30, 20, 3]]

df = pd.DataFrame(data)

Try it Yourself »

Definition and Usage

The pct_change() method returns a DataFrame with the percentage difference between the values for each row and, by default, the previous row.

Which row to compare with can be specified with the periods parameter.


dataframe.pct_change(periods, axis, fill_method, limit, freq, kwargs)


The periods, fill_method, axis, limit , freq parameters are keyword arguments..

Parameter Value Description
periods a number Optional. Specifies which row/column to calculate the difference between. Default 1, which means the previous row/column.
axis 0
Optional, default 0, specifies the axis to check the difference between.
fill_method String Optional, default 'pad'. Specifies how to deal with NULL values.
limit None
Optional, default None. Specifies how many NULL values to fill before ending the comparison.
freq Date
Optional, Specifies the increment to use for datetime values.

 Return Value

A DataFrame object with the differences.

❮ DataFrame Reference