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


Series.diff(self, periods=1)
Pandas Series difference image


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

Returns: Series
First differences of the Series


Download the above Notebook from here.

Previous: Generate descriptive statistics in Pandas
Next: Encode the object in Pandas

Share this Tutorial / Exercise on : Facebook and Twitter