# xarray.core.coordinates.DataTreeCoordinates.assign

#### DataTreeCoordinates.assign(coords=None, \*\*coords_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/coordinates.py#L666-L719)

Assign new coordinates (and indexes) to a Coordinates object.

Return a new object with all the original coordinates in addition to the
new ones.

* **Parameters:**
  * **coords** ([mapping](https://docs.python.org/3/glossary.html#term-mapping) of `dim` to `coord`, *optional*) – A mapping whose keys are the names of the coordinates and values are the
    coordinates to assign. The mapping will generally be a dict or
    [`Coordinates`](xarray.Coordinates.html.md#xarray.Coordinates).
    * If a value is a standard data value — for example, a `DataArray`,
      scalar, or array — the data is simply assigned as a coordinate.
    * A coordinate can also be defined and attached to an existing dimension
      using a tuple with the first element the dimension name and the second
      element the values for this new coordinate.
  * **\*\*coords_kwargs** – The keyword arguments form of `coords`.
    One of `coords` or `coords_kwargs` must be provided.
* **Returns:**
  **new_coords** ([`Coordinates`](xarray.Coordinates.html.md#xarray.Coordinates)) – A new Coordinates object with the new coordinates (and indexes)
  in addition to all the existing coordinates.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('bee79cef-dc24-4f1c-81ee-cdea4062df43','a4b99e21-8ff2-4f20-a7b6-518961f0415e','7e5a4f49-925a-40c4-b1b2-bc558e4699a9','../lite/tree/../notebooks/index.html?path=d6f8e1d1_8bb6_42e5_828c_be8ec4312825.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> coords = xr.Coordinates()
>>> coords
Coordinates:
    *empty*
```

```pycon
>>> coords.assign(x=[1, 2])
Coordinates:
  * x        (x) int64 16B 1 2
```

```pycon
>>> midx = pd.MultiIndex.from_product([["a", "b"], [0, 1]])
>>> coords.assign(xr.Coordinates.from_pandas_multiindex(midx, "y"))
Coordinates:
  * y          (y) object 32B MultiIndex
  * y_level_0  (y) object 32B 'a' 'a' 'b' 'b'
  * y_level_1  (y) int64 32B 0 1 0 1
```

<div id="7e5a4f49-925a-40c4-b1b2-bc558e4699a9" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('bee79cef-dc24-4f1c-81ee-cdea4062df43','7e5a4f49-925a-40c4-b1b2-bc558e4699a9')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('bee79cef-dc24-4f1c-81ee-cdea4062df43','7e5a4f49-925a-40c4-b1b2-bc558e4699a9')">Open In Tab</button></div><div id="a4b99e21-8ff2-4f20-a7b6-518961f0415e" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
