# xarray.Dataset.dropna

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

Returns a new dataset with dropped labels for missing values 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.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('d14ca9a4-e8d1-4caf-a410-e8db98074919','b476a89b-98dd-4a04-ba93-6ec20c73beba','8f9260ab-51fb-49dc-8998-99a02b1a0481','../lite/tree/../notebooks/index.html?path=b7599253_8c11_408c_adfd_815a289e61d1.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="8f9260ab-51fb-49dc-8998-99a02b1a0481" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('d14ca9a4-e8d1-4caf-a410-e8db98074919','8f9260ab-51fb-49dc-8998-99a02b1a0481')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('d14ca9a4-e8d1-4caf-a410-e8db98074919','8f9260ab-51fb-49dc-8998-99a02b1a0481')">Open In Tab</button></div><div id="b476a89b-98dd-4a04-ba93-6ec20c73beba" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
* **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)
