# xarray.DataArray.rolling

#### DataArray.rolling(dim=None, min_periods=None, center=False, \*\*window_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L7420-L7493)

Rolling window object for DataArrays.

* **Parameters:**
  * **dim** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), *optional*) – Mapping from the dimension name to create the rolling iterator
    along (e.g. time) to its moving window size.
  * **min_periods** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Minimum number of observations in window required to have a value
    (otherwise result is NA). The default, None, is equivalent to
    setting min_periods equal to the size of the window.
  * **center** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or `Mapping` to [`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Set the labels at the center of the window. The default, False,
    sets the labels at the right edge of the window.
  * **\*\*window_kwargs** (**optional**) – The keyword arguments form of `dim`.
    One of dim or window_kwargs must be provided.
* **Returns:**
  [`computation.rolling.DataArrayRolling`](xarray.computation.rolling.DataArrayRolling.html.md#xarray.computation.rolling.DataArrayRolling)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('86201a47-6e89-46f6-b1e9-751dada7dfe3','e683a37c-297e-43c8-857b-0fd1819abf59','b3dddde5-040d-4207-910e-6861f515a062','../lite/tree/../notebooks/index.html?path=14b8a192_aea5_42dc_86f4_5e8828b18cc4.ipynb','None')">Try it in your browser!</button></div>

Create rolling seasonal average of monthly data e.g. DJF, JFM, …, SON:

```pycon
>>> da = xr.DataArray(
...     np.linspace(0, 11, num=12),
...     coords=[
...         pd.date_range(
...             "1999-12-15",
...             periods=12,
...             freq=pd.DateOffset(months=1),
...         )
...     ],
...     dims="time",
... )
>>> da
<xarray.DataArray (time: 12)> Size: 96B
array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 11.])
Coordinates:
  * time     (time) datetime64[us] 96B 1999-12-15 2000-01-15 ... 2000-11-15
>>> da.rolling(time=3, center=True).mean()
<xarray.DataArray (time: 12)> Size: 96B
array([nan,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., nan])
Coordinates:
  * time     (time) datetime64[us] 96B 1999-12-15 2000-01-15 ... 2000-11-15
```

Remove the NaNs using `dropna()`:

```pycon
>>> da.rolling(time=3, center=True).mean().dropna("time")
<xarray.DataArray (time: 10)> Size: 80B
array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])
Coordinates:
  * time     (time) datetime64[us] 80B 2000-01-15 2000-02-15 ... 2000-10-15
```

<div id="b3dddde5-040d-4207-910e-6861f515a062" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('86201a47-6e89-46f6-b1e9-751dada7dfe3','b3dddde5-040d-4207-910e-6861f515a062')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('86201a47-6e89-46f6-b1e9-751dada7dfe3','b3dddde5-040d-4207-910e-6861f515a062')">Open In Tab</button></div><div id="e683a37c-297e-43c8-857b-0fd1819abf59" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.cumulative`](xarray.DataArray.cumulative.html.md#xarray.DataArray.cumulative), [`Dataset.rolling`](xarray.Dataset.rolling.html.md#xarray.Dataset.rolling), [`computation.rolling.DataArrayRolling`](xarray.computation.rolling.DataArrayRolling.html.md#xarray.computation.rolling.DataArrayRolling)
