cudf.DataFrame.diff#

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

First discrete difference of element.

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

Parameters:
periodsint, default 1

Periods to shift for calculating difference, accepts negative values.

axis{0 or ‘index’, 1 or ‘columns’}, default 0

Take difference over rows (0) or columns (1). Only row-wise (0) shift is supported.

Returns:
DataFrame

First differences of the DataFrame.

Examples

>>> import cudf
>>> gdf = cudf.DataFrame({'a': [1, 2, 3, 4, 5, 6],
...                       'b': [1, 1, 2, 3, 5, 8],
...                       'c': [1, 4, 9, 16, 25, 36]})
>>> gdf
   a  b   c
0  1  1   1
1  2  1   4
2  3  2   9
3  4  3  16
4  5  5  25
5  6  8  36
>>> gdf.diff(periods=2)
      a     b     c
0  <NA>  <NA>  <NA>
1  <NA>  <NA>  <NA>
2     2     1     8
3     2     2    12
4     2     3    16
5     2     5    20

Pandas Compatibility Note

pandas.DataFrame.diff()

Diff currently only supports numeric dtype columns.