- final Index.diff(periods=1)#
Computes the difference between consecutive values in the Index object.
If periods is greater than 1, computes the difference between values that are periods number of positions apart.
- periodsint, optional
The number of positions between the current and previous value to compute the difference with. Default is 1.
A new Index object with the computed differences.
>>> import pandas as pd >>> idx = pd.Index([10, 20, 30, 40, 50]) >>> idx.diff() Index([nan, 10.0, 10.0, 10.0, 10.0], dtype='float64')