Examples
import numpy as np
import pandas as pd
df = pd.DataFrame({'p': [2, 3, 4, 5, 6, 7],
'q': [2, 2, 3, 5, 8, 10],
'r': [4, 9, 16, 24, 36, 40]})
df
df.diff()
Difference with previous column:
df.diff(axis=1)
Difference with 3rd previous row:
df.diff(periods=3)
Difference with following row:
df.diff(periods=-1)