cudf.Series.diff#
- Series.diff(periods=1)#
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).
- Parameters
- periodsint, default 1
Periods to shift for calculating difference, accepts negative values.
- Returns
- Series
First differences of the Series.
Examples
>>> import cudf >>> series = cudf.Series([1, 1, 2, 3, 5, 8]) >>> series 0 1 1 1 2 2 3 3 4 5 5 8 dtype: int64
Difference with previous row
>>> series.diff() 0 <NA> 1 0 2 1 3 1 4 2 5 3 dtype: int64
Difference with 3rd previous row
>>> series.diff(periods=3) 0 <NA> 1 <NA> 2 <NA> 3 2 4 4 5 6 dtype: int64
Difference with following row
>>> series.diff(periods=-1) 0 0 1 -1 2 -1 3 -2 4 -3 5 <NA> dtype: int64