w3resource

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)
Pandas Series difference image

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.



Inviting useful, relevant, well-written and unique guest posts