cudf.Series.diff#

Series.diff(periods=1)#

Calculate the difference between values at positions i and i - N in an array and store the output in a new array.

Returns
Series

First differences of the Series.

Notes

Diff currently only supports float and integer dtype columns with no null values.

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