# xarray.DataArray.fillna

#### DataArray.fillna(value)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L3624-L3683)

Fill missing values in this object.

This operation follows the normal broadcasting and alignment rules that
xarray uses for binary arithmetic, except the result is aligned to this
object (`join='left'`) instead of aligned to the intersection of
index coordinates (`join='inner'`).

* **Parameters:**
  **value** ([scalar](../user-guide/terminology.html.md#term-scalar), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) or [`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Used to fill all matching missing values in this array. If the
  argument is a DataArray, it is first aligned with (reindexed to)
  this array.
* **Returns:**
  **filled** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray))

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('131f0dd1-09b7-4424-9302-c4d77c490a81','5bc74973-b1fd-440c-97f3-bbad091c0459','91bff174-297a-4125-b3c6-46d3a221ac29','../lite/tree/../notebooks/index.html?path=c5059236_4e3e_47a8_bd01_23056e4e80c0.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(
...     np.array([1, 4, np.nan, 0, 3, np.nan]),
...     dims="Z",
...     coords=dict(
...         Z=("Z", np.arange(6)),
...         height=("Z", np.array([0, 10, 20, 30, 40, 50])),
...     ),
... )
>>> da
<xarray.DataArray (Z: 6)> Size: 48B
array([ 1.,  4., nan,  0.,  3., nan])
Coordinates:
  * Z        (Z) int64 48B 0 1 2 3 4 5
    height   (Z) int64 48B 0 10 20 30 40 50
```

Fill all NaN values with 0:

```pycon
>>> da.fillna(0)
<xarray.DataArray (Z: 6)> Size: 48B
array([1., 4., 0., 0., 3., 0.])
Coordinates:
  * Z        (Z) int64 48B 0 1 2 3 4 5
    height   (Z) int64 48B 0 10 20 30 40 50
```

Fill NaN values with corresponding values in array:

```pycon
>>> da.fillna(np.array([2, 9, 4, 2, 8, 9]))
<xarray.DataArray (Z: 6)> Size: 48B
array([1., 4., 4., 0., 3., 9.])
Coordinates:
  * Z        (Z) int64 48B 0 1 2 3 4 5
    height   (Z) int64 48B 0 10 20 30 40 50
```

<div id="91bff174-297a-4125-b3c6-46d3a221ac29" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('131f0dd1-09b7-4424-9302-c4d77c490a81','91bff174-297a-4125-b3c6-46d3a221ac29')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('131f0dd1-09b7-4424-9302-c4d77c490a81','91bff174-297a-4125-b3c6-46d3a221ac29')">Open In Tab</button></div><div id="5bc74973-b1fd-440c-97f3-bbad091c0459" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
