# xarray.DataArray.set_index

#### DataArray.set_index(indexes=None, append=False, \*\*indexes_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L2894-L2955)

Set DataArray (multi-)indexes using one or more existing
coordinates.

This legacy method is limited to pandas (multi-)indexes and
1-dimensional “dimension” coordinates. See
[`set_xindex()`](xarray.DataArray.set_xindex.html.md#xarray.DataArray.set_xindex) for setting a pandas or a custom
Xarray-compatible index from one or more arbitrary coordinates.

* **Parameters:**
  * **indexes** (`{dim: index, ...}`) – Mapping from names matching dimensions and values given
    by (lists of) the names of existing coordinates or variables to set
    as new (multi-)index.
  * **append** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If True, append the supplied index(es) to the existing index(es).
    Otherwise replace the existing index(es).
  * **\*\*indexes_kwargs** (**optional**) – The keyword arguments form of `indexes`.
    One of indexes or indexes_kwargs must be provided.
* **Returns:**
  **obj** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Another DataArray, with this data but replaced coordinates.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('5d8ae0ad-b7ed-48b9-8ed6-75d07211953c','71134424-128a-4a93-a1c7-2f5e63c20b3d','d5ee7ef7-5c8b-4760-881d-ce4f37a7f01c','../lite/tree/../notebooks/index.html?path=2a970112_39d0_41ad_bde5_b21b86dffff5.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> arr = xr.DataArray(
...     data=np.ones((2, 3)),
...     dims=["x", "y"],
...     coords={"x": range(2), "y": range(3), "a": ("x", [3, 4])},
... )
>>> arr
<xarray.DataArray (x: 2, y: 3)> Size: 48B
array([[1., 1., 1.],
       [1., 1., 1.]])
Coordinates:
  * x        (x) int64 16B 0 1
    a        (x) int64 16B 3 4
  * y        (y) int64 24B 0 1 2
>>> arr.set_index(x="a")
<xarray.DataArray (x: 2, y: 3)> Size: 48B
array([[1., 1., 1.],
       [1., 1., 1.]])
Coordinates:
  * x        (x) int64 16B 3 4
  * y        (y) int64 24B 0 1 2
```

<div id="d5ee7ef7-5c8b-4760-881d-ce4f37a7f01c" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('5d8ae0ad-b7ed-48b9-8ed6-75d07211953c','d5ee7ef7-5c8b-4760-881d-ce4f37a7f01c')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('5d8ae0ad-b7ed-48b9-8ed6-75d07211953c','d5ee7ef7-5c8b-4760-881d-ce4f37a7f01c')">Open In Tab</button></div><div id="71134424-128a-4a93-a1c7-2f5e63c20b3d" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.reset_index`](xarray.DataArray.reset_index.html.md#xarray.DataArray.reset_index), [`DataArray.set_xindex`](xarray.DataArray.set_xindex.html.md#xarray.DataArray.set_xindex)
