# xarray.DataArray.drop_duplicates

#### DataArray.drop_duplicates(dim, , keep='first')[[source]](https://github.com/pydata/xarray/blob/v2026.09.0/xarray/core/dataarray.py#L6820-L6898)

Returns a new DataArray with duplicate dimension values removed.

* **Parameters:**
  * **dim** (`dimension label` or `labels`) – Pass … to drop duplicates along all dimensions.
  * **keep** (`{"first", "last", False}`, *default*: `"first"`) – Determines which duplicates (if any) to keep.
    - `"first"` : Drop duplicates except for the first occurrence.
    - `"last"` : Drop duplicates except for the last occurrence.
    - False : Drop all duplicates.
* **Returns:**
  [`DataArray`](xarray.DataArray.html.md#xarray.DataArray)

#### SEE ALSO
[`Dataset.drop_duplicates`](xarray.Dataset.drop_duplicates.html.md#xarray.Dataset.drop_duplicates)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('e23bfa9e-c26c-4b08-a6c4-8c86bc6bb3c1','750681bb-c9d3-445f-ac97-7ce2fa0c24ff','a7242dfc-9738-43e0-a45b-8baab488f21a','../lite/tree/../notebooks/index.html?path=370046a8_d2e5_4251_8b6b_3b1fe68547e7.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(
...     np.arange(25).reshape(5, 5),
...     dims=("x", "y"),
...     coords={"x": np.array([0, 0, 1, 2, 3]), "y": np.array([0, 1, 2, 3, 3])},
... )
>>> da
<xarray.DataArray (x: 5, y: 5)> Size: 200B
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24]])
Coordinates:
  * x        (x) int64 40B 0 0 1 2 3
  * y        (y) int64 40B 0 1 2 3 3
```

```pycon
>>> da.drop_duplicates(dim="x")
<xarray.DataArray (x: 4, y: 5)> Size: 160B
array([[ 0,  1,  2,  3,  4],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24]])
Coordinates:
  * x        (x) int64 32B 0 1 2 3
  * y        (y) int64 40B 0 1 2 3 3
```

```pycon
>>> da.drop_duplicates(dim="x", keep="last")
<xarray.DataArray (x: 4, y: 5)> Size: 160B
array([[ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24]])
Coordinates:
  * x        (x) int64 32B 0 1 2 3
  * y        (y) int64 40B 0 1 2 3 3
```

Drop all duplicate dimension values:

```pycon
>>> da.drop_duplicates(dim=...)
<xarray.DataArray (x: 4, y: 4)> Size: 128B
array([[ 0,  1,  2,  3],
       [10, 11, 12, 13],
       [15, 16, 17, 18],
       [20, 21, 22, 23]])
Coordinates:
  * x        (x) int64 32B 0 1 2 3
  * y        (y) int64 32B 0 1 2 3
```

<div id="a7242dfc-9738-43e0-a45b-8baab488f21a" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e23bfa9e-c26c-4b08-a6c4-8c86bc6bb3c1','a7242dfc-9738-43e0-a45b-8baab488f21a')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e23bfa9e-c26c-4b08-a6c4-8c86bc6bb3c1','a7242dfc-9738-43e0-a45b-8baab488f21a')">Open In Tab</button></div><div id="750681bb-c9d3-445f-ac97-7ce2fa0c24ff" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
