w3resource
Pandas Tutorial

Pandas Series: diff() function

First discrete difference of element in Pandas

The diff() function is used to first discrete difference of element.

Calculates the difference of a Series element compared with another element in the Series (default is element in previous row).

Syntax:

Series.diff(self, periods=1)

Parameters:

Name Description Type/Default Value Required / Optional
periods Periods to shift for calculating difference, accepts negative values. int
Default Value: 1
Required

Returns: Series
First differences of the Series

Example:


Download the above Notebook from here.