pandas.core.groupby.DataFrameGroupBy.diff

DataFrameGroupBy.diff(periods=1, axis=0)[source]

First discrete difference of element.

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

Parameters:
periodsint, default 1

Periods to shift for calculating difference, accepts negative values.

axisaxis to shift, default 0

Take difference over rows (0) or columns (1).

Returns:
Series or DataFrame

First differences.

See also

Series.groupby

Apply a function groupby to a Series.

DataFrame.groupby

Apply a function groupby to each row or column of a DataFrame.