# xarray.Dataset.fillna

#### Dataset.fillna(value)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L6529-L6607)

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), [`DataArray`](xarray.DataArray.html.md#xarray.DataArray), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict) or [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – Used to fill all matching missing values in this dataset’s data
  variables. Scalars, ndarrays or DataArrays arguments are used to
  fill all data with aligned coordinates (for DataArrays).
  Dictionaries or datasets match data variables and then align
  coordinates if necessary.
* **Returns:**
  [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('11163b86-e055-4192-bf62-cb7998d3e94f','28fe6d0f-3f6e-4701-a4d9-3903154bc97a','fc233e19-aed9-4bab-9b25-8defff8f1705','../lite/tree/../notebooks/index.html?path=90a8d763_a171_465b_8aab_f98be1c861af.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> ds = xr.Dataset(
...     {
...         "A": ("x", [np.nan, 2, np.nan, 0]),
...         "B": ("x", [3, 4, np.nan, 1]),
...         "C": ("x", [np.nan, np.nan, np.nan, 5]),
...         "D": ("x", [np.nan, 3, np.nan, 4]),
...     },
...     coords={"x": [0, 1, 2, 3]},
... )
>>> ds
<xarray.Dataset> Size: 160B
Dimensions:  (x: 4)
Coordinates:
  * x        (x) int64 32B 0 1 2 3
Data variables:
    A        (x) float64 32B nan 2.0 nan 0.0
    B        (x) float64 32B 3.0 4.0 nan 1.0
    C        (x) float64 32B nan nan nan 5.0
    D        (x) float64 32B nan 3.0 nan 4.0
```

Replace all NaN values with 0s.

```pycon
>>> ds.fillna(0)
<xarray.Dataset> Size: 160B
Dimensions:  (x: 4)
Coordinates:
  * x        (x) int64 32B 0 1 2 3
Data variables:
    A        (x) float64 32B 0.0 2.0 0.0 0.0
    B        (x) float64 32B 3.0 4.0 0.0 1.0
    C        (x) float64 32B 0.0 0.0 0.0 5.0
    D        (x) float64 32B 0.0 3.0 0.0 4.0
```

Replace all NaN elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively.

```pycon
>>> values = {"A": 0, "B": 1, "C": 2, "D": 3}
>>> ds.fillna(value=values)
<xarray.Dataset> Size: 160B
Dimensions:  (x: 4)
Coordinates:
  * x        (x) int64 32B 0 1 2 3
Data variables:
    A        (x) float64 32B 0.0 2.0 0.0 0.0
    B        (x) float64 32B 3.0 4.0 1.0 1.0
    C        (x) float64 32B 2.0 2.0 2.0 5.0
    D        (x) float64 32B 3.0 3.0 3.0 4.0
```

<div id="fc233e19-aed9-4bab-9b25-8defff8f1705" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('11163b86-e055-4192-bf62-cb7998d3e94f','fc233e19-aed9-4bab-9b25-8defff8f1705')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('11163b86-e055-4192-bf62-cb7998d3e94f','fc233e19-aed9-4bab-9b25-8defff8f1705')">Open In Tab</button></div><div id="28fe6d0f-3f6e-4701-a4d9-3903154bc97a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
