xarray.Dataset.shift¶
-
Dataset.
shift
(shifts=None, fill_value=<NA>, **shifts_kwargs)¶ Shift this dataset by an offset along one or more dimensions.
Only data variables are moved; coordinates stay in place. This is consistent with the behavior of
shift
in pandas.- Parameters
shifts (mapping of hashable to
int
) – Integer offset to shift along each of the given dimensions. Positive offsets shift to the right; negative offsets shift to the left.fill_value (scalar or dict-like, optional) – Value to use for newly missing values. If a dict-like, maps variable names (including coordinates) to fill values.
**shifts_kwargs – The keyword arguments form of
shifts
. One of shifts or shifts_kwargs must be provided.
- Returns
shifted – Dataset with the same coordinates and attributes but shifted data variables.
- Return type
See also
Examples
>>> ds = xr.Dataset({"foo": ("x", list("abcde"))}) >>> ds.shift(x=2) <xarray.Dataset> Dimensions: (x: 5) Dimensions without coordinates: x Data variables: foo (x) object nan nan 'a' 'b' 'c'