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



Follow us on Facebook and Twitter for latest update.