đŸ Xarray is now 10 years old! đ

xarray.Dataset.diff#

Dataset.diff(dim, n=1, *, label='upper')[source]#

Calculate the n-th order discrete difference along given axis.

Parameters:
• dim (Hashable) â Dimension over which to calculate the finite difference.

• n (int, default: 1) â The number of times values are differenced.

• label ({"upper", "lower"}, default: "upper") â The new coordinate in dimension dim will have the values of either the minuendâs or subtrahendâs coordinate for values âupperâ and âlowerâ, respectively.

Returns:

difference (Dataset) â The n-th order finite difference of this object.

Notes

n matches numpyâs behavior and is different from pandasâ first argument named periods.

Examples

>>> ds = xr.Dataset({"foo": ("x", [5, 5, 6, 6])})
>>> ds.diff("x")
<xarray.Dataset> Size: 24B
Dimensions:  (x: 3)
Dimensions without coordinates: x
Data variables:
foo      (x) int64 24B 0 1 0
>>> ds.diff("x", 2)
<xarray.Dataset> Size: 16B
Dimensions:  (x: 2)
Dimensions without coordinates: x
Data variables:
foo      (x) int64 16B 1 -1