# xarray.DataArray.drop_duplicates

#### DataArray.drop_duplicates(dim, , keep='first')[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L6906-L6984)

Return 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('93d7c3e1-b0cf-4e80-b70d-1bf67c8ad2d1','2233ff2f-2ccc-4673-9ad1-1e945a295723','fa5483e0-30d6-4416-9a2c-6ea6e3048750','../lite/tree/../notebooks/index.html?path=9a7e8f77_bd11_49ea_92ec_f0e9ca1b206a.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="fa5483e0-30d6-4416-9a2c-6ea6e3048750" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('93d7c3e1-b0cf-4e80-b70d-1bf67c8ad2d1','fa5483e0-30d6-4416-9a2c-6ea6e3048750')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('93d7c3e1-b0cf-4e80-b70d-1bf67c8ad2d1','fa5483e0-30d6-4416-9a2c-6ea6e3048750')">Open In Tab</button></div><div id="2233ff2f-2ccc-4673-9ad1-1e945a295723" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
