# xarray.Coordinates

### *class* xarray.Coordinates(coords=None, indexes=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/coordinates.py#L202-L881)

Dictionary like container for Xarray coordinates (variables + indexes).

This collection is a mapping of coordinate names to
[`DataArray`](xarray.DataArray.html.md#xarray.DataArray) objects.

It can be passed directly to the [`Dataset`](xarray.Dataset.html.md#xarray.Dataset) and
[`DataArray`](xarray.DataArray.html.md#xarray.DataArray) constructors via their coords argument. This
will add both the coordinates variables and their index.

Coordinates are either:

- returned via the [`Dataset.coords`](xarray.Dataset.coords.html.md#xarray.Dataset.coords), [`DataArray.coords`](xarray.DataArray.coords.html.md#xarray.DataArray.coords),
  and [`DataTree.coords`](xarray.DataTree.coords.html.md#xarray.DataTree.coords) properties,
- built from Xarray or Pandas index objects
  (e.g., [`Coordinates.from_xindex()`](xarray.Coordinates.from_xindex.html.md#xarray.Coordinates.from_xindex) or
  [`Coordinates.from_pandas_multiindex()`](xarray.Coordinates.from_pandas_multiindex.html.md#xarray.Coordinates.from_pandas_multiindex)),
- built manually from input coordinate data and Xarray `Index` objects via
  [`Coordinates.__init__()`](#xarray.Coordinates.__init__) (beware that no consistency check is done
  on those inputs).

To create new coordinates from an existing Xarray `Index` object, use
[`Coordinates.from_xindex()`](xarray.Coordinates.from_xindex.html.md#xarray.Coordinates.from_xindex) instead of
[`Coordinates.__init__()`](#xarray.Coordinates.__init__). The latter is useful, e.g., for creating
coordinates with no default index.

* **Parameters:**
  * **coords** ([dict-like](https://docs.python.org/3/glossary.html#term-mapping), *optional*) – Mapping where keys are coordinate names and values are objects that
    can be converted into a [`Variable`](xarray.Variable.html.md#xarray.Variable) object
    (see [`as_variable()`](xarray.as_variable.html.md#xarray.as_variable)). If another
    [`Coordinates`](#xarray.Coordinates) object is passed, its indexes
    will be added to the new created object.
  * **indexes** ([dict-like](https://docs.python.org/3/glossary.html#term-mapping), *optional*) – Mapping where keys are coordinate names and values are
    `Index` objects. If None (default),
    pandas indexes will be created for each dimension coordinate.
    Passing an empty dictionary will skip this default behavior.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('76da4d8c-fb1e-456b-b41e-5a4619ad6d19','6f144777-b4fc-4157-be6a-1605285950e2','d7c5110c-4ff7-4ac2-baba-2feb919f5769','../lite/tree/../notebooks/index.html?path=096d6572_b42a_4b40_be0e_77dc57930f1f.ipynb','None')">Try it in your browser!</button></div>

Create a dimension coordinate with a default (pandas) index:

```pycon
>>> xr.Coordinates({"x": [1, 2]})
Coordinates:
  * x        (x) int64 16B 1 2
```

Create a dimension coordinate with no index:

```pycon
>>> xr.Coordinates(coords={"x": [1, 2]}, indexes={})
Coordinates:
    x        (x) int64 16B 1 2
```

Create a new Coordinates object from existing dataset coordinates
(indexes are passed):

```pycon
>>> ds = xr.Dataset(coords={"x": [1, 2]})
>>> xr.Coordinates(ds.coords)
Coordinates:
  * x        (x) int64 16B 1 2
```

Create indexed coordinates from a `pandas.MultiIndex` object:

```pycon
>>> midx = pd.MultiIndex.from_product([["a", "b"], [0, 1]])
>>> xr.Coordinates.from_pandas_multiindex(midx, "x")
Coordinates:
  * x          (x) object 32B MultiIndex
  * x_level_0  (x) object 32B 'a' 'a' 'b' 'b'
  * x_level_1  (x) int64 32B 0 1 0 1
```

Create a new Dataset object by passing a Coordinates object:

```pycon
>>> midx_coords = xr.Coordinates.from_pandas_multiindex(midx, "x")
>>> xr.Dataset(coords=midx_coords)
<xarray.Dataset> Size: 96B
Dimensions:    (x: 4)
Coordinates:
  * x          (x) object 32B MultiIndex
  * x_level_0  (x) object 32B 'a' 'a' 'b' 'b'
  * x_level_1  (x) int64 32B 0 1 0 1
Data variables:
    *empty*
```

<div id="d7c5110c-4ff7-4ac2-baba-2feb919f5769" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('76da4d8c-fb1e-456b-b41e-5a4619ad6d19','d7c5110c-4ff7-4ac2-baba-2feb919f5769')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('76da4d8c-fb1e-456b-b41e-5a4619ad6d19','d7c5110c-4ff7-4ac2-baba-2feb919f5769')">Open In Tab</button></div><div id="6f144777-b4fc-4157-be6a-1605285950e2" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### \_\_init_\_(coords=None, indexes=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/coordinates.py#L292-L355)

### Methods

| [`__init__`](#xarray.Coordinates.__init__)([coords, indexes])                                                 |                                                                                                                                                     |
|------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| [`assign`](xarray.Coordinates.assign.html.md#xarray.Coordinates.assign)([coords])                                  | Assign new coordinates (and indexes) to a Coordinates object, returning a new object with all the original coordinates in addition to the new ones. |
| [`copy`](xarray.Coordinates.copy.html.md#xarray.Coordinates.copy)([deep, memo])                                  | Return a copy of this Coordinates object.                                                                                                           |
| [`drop_dims`](xarray.Coordinates.drop_dims.html.md#xarray.Coordinates.drop_dims)(drop_dims, \*[, errors])             | Drop dimensions and associated variables from this dataset.                                                                                         |
| [`drop_vars`](xarray.Coordinates.drop_vars.html.md#xarray.Coordinates.drop_vars)(names, \*[, errors])                 | Drop variables from this Coordinates object.                                                                                                        |
| [`equals`](xarray.Coordinates.equals.html.md#xarray.Coordinates.equals)(other)                                     | Two Coordinates objects are equal if they have matching variables, all of which are equal.                                                          |
| [`from_pandas_multiindex`](xarray.Coordinates.from_pandas_multiindex.html.md#xarray.Coordinates.from_pandas_multiindex)(midx, dim) | Wrap a pandas multi-index as Xarray coordinates (dimension + levels).                                                                               |
| [`from_xindex`](xarray.Coordinates.from_xindex.html.md#xarray.Coordinates.from_xindex)(index)                           | Create Xarray coordinates from an existing Xarray index.                                                                                            |
| [`get`](xarray.Coordinates.get.html.md#xarray.Coordinates.get)(k[,d])                                           |                                                                                                                                                     |
| [`identical`](xarray.Coordinates.identical.html.md#xarray.Coordinates.identical)(other)                               | Like equals, but also checks all variable attributes.                                                                                               |
| [`items`](xarray.Coordinates.items.html.md#xarray.Coordinates.items)()                                            |                                                                                                                                                     |
| [`keys`](xarray.Coordinates.keys.html.md#xarray.Coordinates.keys)()                                              |                                                                                                                                                     |
| [`merge`](xarray.Coordinates.merge.html.md#xarray.Coordinates.merge)(other, \*[, compat])                         | Merge two sets of coordinates to create a new Dataset                                                                                               |
| [`rename_dims`](xarray.Coordinates.rename_dims.html.md#xarray.Coordinates.rename_dims)([dims_dict])                     | Returns a new object with renamed dimensions only.                                                                                                  |
| [`rename_vars`](xarray.Coordinates.rename_vars.html.md#xarray.Coordinates.rename_vars)([name_dict])                     | Returns a new object with renamed variables.                                                                                                        |
| [`to_dataset`](xarray.Coordinates.to_dataset.html.md#xarray.Coordinates.to_dataset)()                                  | Convert these coordinates into a new Dataset.                                                                                                       |
| [`to_index`](xarray.Coordinates.to_index.html.md#xarray.Coordinates.to_index)([ordered_dims])                        | Convert all index coordinates into a [`pandas.Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index).   |
| [`update`](xarray.Coordinates.update.html.md#xarray.Coordinates.update)(other)                                     | Update this Coordinates variables with other coordinate variables.                                                                                  |
| [`values`](xarray.Coordinates.values.html.md#xarray.Coordinates.values)()                                          |                                                                                                                                                     |

### Attributes

| [`dims`](xarray.Coordinates.dims.html.md#xarray.Coordinates.dims)           | Mapping from dimension names to lengths or tuple of dimension names.     |
|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| [`dtypes`](xarray.Coordinates.dtypes.html.md#xarray.Coordinates.dtypes)       | Mapping from coordinate names to dtypes.                                 |
| [`indexes`](xarray.Coordinates.indexes.html.md#xarray.Coordinates.indexes)     | Mapping of pandas.Index objects used for label based indexing.           |
| [`sizes`](xarray.Coordinates.sizes.html.md#xarray.Coordinates.sizes)         | Mapping from dimension names to lengths.                                 |
| [`variables`](xarray.Coordinates.variables.html.md#xarray.Coordinates.variables) | Low level interface to Coordinates contents as dict of Variable objects. |
| [`xindexes`](xarray.Coordinates.xindexes.html.md#xarray.Coordinates.xindexes)   | Mapping of `Index` objects used for label based indexing.                |
