# xarray.Dataset.dropna

#### Dataset.dropna(dim, , how='any', thresh=None, subset=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L6426-L6559)

Return a new dataset with dropped labels for missing values.

The labels are dropped along the provided dimension.

* **Parameters:**
  * **dim** ([hashable](../user-guide/terminology.html.md#term-name)) – Dimension along which to drop missing values. Dropping along
    multiple dimensions simultaneously is not yet supported.
  * **how** (`{"any", "all"}`, *default*: `"any"`) –
    - any : if any NA values are present, drop that label
    - all : if all values are NA, drop that label
  * **thresh** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If supplied, require this many non-NA values (summed over all the subset variables).
  * **subset** ([iterable](https://docs.python.org/3/glossary.html#term-iterable) of [hashable](../user-guide/terminology.html.md#term-name) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – Which variables to check for missing values. By default, all
    variables in the dataset are checked.
* **Returns:**
  [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)

#### SEE ALSO
[`DataArray.dropna`](xarray.DataArray.dropna.html.md#xarray.DataArray.dropna), [`pandas.DataFrame.dropna`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html#pandas.DataFrame.dropna)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('52803345-6288-46db-82a9-5a9d44b988ff','57b5428d-9bcd-4d01-b9ca-cb8a6a5cfeda','84dd5015-6a33-4d63-b860-e2819b527bb4','../lite/tree/../notebooks/index.html?path=3141d2d5_f1a4_462e_83b5_9bab77c78335.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> dataset = xr.Dataset(
...     {
...         "temperature": (
...             ["time", "location"],
...             [[23.4, 24.1], [np.nan, 22.1], [21.8, 24.2], [20.5, 25.3]],
...         )
...     },
...     coords={"time": [1, 2, 3, 4], "location": ["A", "B"]},
... )
>>> dataset
<xarray.Dataset> Size: 104B
Dimensions:      (time: 4, location: 2)
Coordinates:
  * time         (time) int64 32B 1 2 3 4
  * location     (location) <U1 8B 'A' 'B'
Data variables:
    temperature  (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
```

Drop NaN values from the dataset

```pycon
>>> dataset.dropna(dim="time")
<xarray.Dataset> Size: 80B
Dimensions:      (time: 3, location: 2)
Coordinates:
  * time         (time) int64 24B 1 3 4
  * location     (location) <U1 8B 'A' 'B'
Data variables:
    temperature  (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
```

Drop labels with any NaN values

```pycon
>>> dataset.dropna(dim="time", how="any")
<xarray.Dataset> Size: 80B
Dimensions:      (time: 3, location: 2)
Coordinates:
  * time         (time) int64 24B 1 3 4
  * location     (location) <U1 8B 'A' 'B'
Data variables:
    temperature  (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
```

Drop labels with all NAN values

```pycon
>>> dataset.dropna(dim="time", how="all")
<xarray.Dataset> Size: 104B
Dimensions:      (time: 4, location: 2)
Coordinates:
  * time         (time) int64 32B 1 2 3 4
  * location     (location) <U1 8B 'A' 'B'
Data variables:
    temperature  (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
```

Drop labels with less than 2 non-NA values

```pycon
>>> dataset.dropna(dim="time", thresh=2)
<xarray.Dataset> Size: 80B
Dimensions:      (time: 3, location: 2)
Coordinates:
  * time         (time) int64 24B 1 3 4
  * location     (location) <U1 8B 'A' 'B'
Data variables:
    temperature  (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
```

<div id="84dd5015-6a33-4d63-b860-e2819b527bb4" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('52803345-6288-46db-82a9-5a9d44b988ff','84dd5015-6a33-4d63-b860-e2819b527bb4')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('52803345-6288-46db-82a9-5a9d44b988ff','84dd5015-6a33-4d63-b860-e2819b527bb4')">Open In Tab</button></div><div id="57b5428d-9bcd-4d01-b9ca-cb8a6a5cfeda" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
