pandas.Index.diff#

Index.diff(periods=1)[source]#

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.

Parameters:
periodsint, optional

The number of positions between the current and previous value to compute the difference with. Default is 1.

Returns:
Index

A new Index object with the computed differences.

Examples

>>> 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')