Examples
Series
import numpy as np
import pandas as pd
s = pd.Series([80, 81, 75])
s
s.pct_change()
s.pct_change(periods=2)
See the percentage change in a Series where filling NAs with last valid observation forward to next valid.
s = pd.Series([80, 81, None, 75])
s
s.pct_change(fill_method='ffill')
DataFrame
Percentage change in French franc, Deutsche Mark, and Italian lira from 2000-01-01 to 2000-03-01.
df = pd.DataFrame({
'FR': [5.0505, 5.0963, 5.3149],
'GR': [2.7246, 2.7482, 2.8519],
'IT': [904.74, 910.01, 960.13]},
index=['2000-01-01', '2000-02-01', '2000-03-01'])
df
df.pct_change()
Percentage of change in GOOG and APPL stock volume. Shows computing the percentage
change between columns.
df = pd.DataFrame({
'2019': [1869950, 32586265],
'2018': [1600923, 42912316],
'2017': [1471819, 42403351]},
index=['GOOG', 'APPL'])
df
df.pct_change(axis='columns')