Think of pct_change as asking how much the current value moved relative to the value immediately before it. It returns fractional changes, so 0.5 represents a 50% increase. section 7.4
Comparing successive sales values
For sales of 100, 150, 200, and 250, df['sales'].pct_change() returns NaN, 0.500000, 0.333333, and 0.250000. The first position is NaN because no earlier value exists; later results use (later − earlier) / earlier. section 7.4
Use pct_change effectively by aligning the data so that the rows represent the comparisons you intend:
- Transpose with .T when the values to compare are arranged in columns, because pct_change compares rows in this workflow. section 7.6
- Use diff instead when you need raw changes rather than relative or percentage changes. section 7.4
