# xarray.DataArray.drop_duplicates

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

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('0094dd5a-c832-486a-ac6c-a439b8949a58','039f82ce-46a5-4d03-8b01-daa8103cf53b','008b692f-ff68-4fe0-840a-e87018cf6d1e','../lite/tree/../notebooks/index.html?path=7d5cb5e1_9f5d_4cb6_8488_8e362a0d62ba.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="008b692f-ff68-4fe0-840a-e87018cf6d1e" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('0094dd5a-c832-486a-ac6c-a439b8949a58','008b692f-ff68-4fe0-840a-e87018cf6d1e')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('0094dd5a-c832-486a-ac6c-a439b8949a58','008b692f-ff68-4fe0-840a-e87018cf6d1e')">Open In Tab</button></div><div id="039f82ce-46a5-4d03-8b01-daa8103cf53b" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
