shift
- UnitsAwareDataArray.shift(shifts: Mapping[Any, int] | None = None, fill_value: Any = <NA>, **shifts_kwargs: int) Self
Shift this DataArray by an offset along one or more dimensions.
Only the data is moved; coordinates stay in place. This is consistent with the behavior of
shift
in pandas.Values shifted from beyond array bounds will appear at one end of each dimension, which are filled according to fill_value. For periodic offsets instead see roll.
- Parameters:
shifts (mapping of Hashable to int or None, optional) – 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, optional) – Value to use for newly missing values
**shifts_kwargs – The keyword arguments form of
shifts
. One of shifts or shifts_kwargs must be provided.
- Returns:
shifted – DataArray with the same coordinates and attributes but shifted data.
- Return type:
DataArray
See also
Examples
>>> arr = xr.DataArray([5, 6, 7], dims="x") >>> arr.shift(x=1) <xarray.DataArray (x: 3)> Size: 24B array([nan, 5., 6.]) Dimensions without coordinates: x