pandas.core.groupby.SeriesGroupBy.diff#
- SeriesGroupBy.diff(periods=1, axis=_NoDefault.no_default)[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).
Deprecated since version 2.1.0: For axis=1, operate on the underlying object instead. Otherwise the axis keyword is not necessary.
- 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.