# 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('260419b1-e081-46ae-8ad5-b8804b5f5b71','6ad7c22f-3bb3-46c3-8dd0-31f858a1735e','8d542a6b-d3d0-47b3-9b73-77a94d312894','../lite/tree/../notebooks/index.html?path=5e9038c8_7410_4cd4_8852_376aa75a3c9d.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="8d542a6b-d3d0-47b3-9b73-77a94d312894" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('260419b1-e081-46ae-8ad5-b8804b5f5b71','8d542a6b-d3d0-47b3-9b73-77a94d312894')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('260419b1-e081-46ae-8ad5-b8804b5f5b71','8d542a6b-d3d0-47b3-9b73-77a94d312894')">Open In Tab</button></div><div id="6ad7c22f-3bb3-46c3-8dd0-31f858a1735e" 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)
