Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Pandas DataFrame: diff() function

DataFrame - diff() function

The diff() function calculates the difference of a DataFrame element compared with another element in the DataFrame.

Syntax:

DataFrame.diff(self, periods=1, axis=0)

Parameters:

Name Description Type/Default Value Required / Optional
periods  Periods to shift for calculating difference, accepts negative values. int
Default Value: 1
Required
axis    Take difference over rows (0) or columns (1). {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required

Returns: DataFrame

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - describe() function
Next: DataFrame - eval() function