# xarray.DataArray.reindex_like

#### DataArray.reindex_like(other, \*, method=None, tolerance=None, copy=True, fill_value=<NA>)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L2113-L2297)

Conform this object onto the indexes of another object, for indexes which the
objects share. Missing values are filled with `fill_value`. The default fill
value is NaN.

* **Parameters:**
  * **other** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset) or [`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Object with an ‘indexes’ attribute giving a mapping from dimension
    names to pandas.Index objects, which provides coordinates upon
    which to index the variables in this dataset. The indexes on this
    other object need not be the same as the indexes on this
    dataset. Any mismatched index values will be filled in with
    NaN, and any mismatched dimension names will simply be ignored.
  * **method** (`{None, "nearest", "pad", "ffill", "backfill", "bfill"}`, *optional*) – Method to use for filling index values from other not found on this
    data array:
    - None (default): don’t fill gaps
    - pad / ffill: propagate last valid index value forward
    - backfill / bfill: propagate next valid index value backward
    - nearest: use nearest valid index value
  * **tolerance** (`float | Iterable[float] | str | None`, *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Maximum distance between original and new labels for inexact
    matches. The values of the index at the matching locations must
    satisfy the equation `abs(index[indexer] - target) <= tolerance`.
    Tolerance may be a scalar value, which applies the same tolerance
    to all values, or list-like, which applies variable tolerance per
    element. List-like must be the same size as the index and its dtype
    must exactly match the index’s type.
  * **copy** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – If `copy=True`, data in the return value is always copied. If
    `copy=False` and reindexing is unnecessary, or can be performed
    with only slice operations, then the output may share memory with
    the input. In either case, a new xarray object is always returned.
  * **fill_value** ([scalar](../user-guide/terminology.html.md#term-scalar) or [dict-like](https://docs.python.org/3/glossary.html#term-mapping), *optional*) – Value to use for newly missing values. If a dict-like, maps
    variable names (including coordinates) to fill values. Use this
    data array’s name to refer to the data array’s values.
* **Returns:**
  **reindexed** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Another dataset array, with this array’s data but coordinates from
  the other object.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('a7ea1cf9-989b-431d-aec1-892afcb2a91a','4f9b93e1-ca11-4184-b24c-d75fa56a7dfa','7d02f469-529d-4ae0-8a00-e617ab877511','../lite/tree/../notebooks/index.html?path=1f80b234_8b60_4a28_aef0_213f5cd281c3.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> data = np.arange(12).reshape(4, 3)
>>> da1 = xr.DataArray(
...     data=data,
...     dims=["x", "y"],
...     coords={"x": [10, 20, 30, 40], "y": [70, 80, 90]},
... )
>>> da1
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
Coordinates:
  * x        (x) int64 32B 10 20 30 40
  * y        (y) int64 24B 70 80 90
>>> da2 = xr.DataArray(
...     data=data,
...     dims=["x", "y"],
...     coords={"x": [40, 30, 20, 10], "y": [90, 80, 70]},
... )
>>> da2
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
Coordinates:
  * x        (x) int64 32B 40 30 20 10
  * y        (y) int64 24B 90 80 70
```

Reindexing with both DataArrays having the same coordinates set, but in different order:

```pycon
>>> da1.reindex_like(da2)
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[11, 10,  9],
       [ 8,  7,  6],
       [ 5,  4,  3],
       [ 2,  1,  0]])
Coordinates:
  * x        (x) int64 32B 40 30 20 10
  * y        (y) int64 24B 90 80 70
```

Reindexing with the other array having additional coordinates:

```pycon
>>> da3 = xr.DataArray(
...     data=data,
...     dims=["x", "y"],
...     coords={"x": [20, 10, 29, 39], "y": [70, 80, 90]},
... )
>>> da1.reindex_like(da3)
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 3.,  4.,  5.],
       [ 0.,  1.,  2.],
       [nan, nan, nan],
       [nan, nan, nan]])
Coordinates:
  * x        (x) int64 32B 20 10 29 39
  * y        (y) int64 24B 70 80 90
```

Filling missing values with the previous valid index with respect to the coordinates’ value:

```pycon
>>> da1.reindex_like(da3, method="ffill")
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[3, 4, 5],
       [0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
Coordinates:
  * x        (x) int64 32B 20 10 29 39
  * y        (y) int64 24B 70 80 90
```

Filling missing values while tolerating specified error for inexact matches:

```pycon
>>> da1.reindex_like(da3, method="ffill", tolerance=5)
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 3.,  4.,  5.],
       [ 0.,  1.,  2.],
       [nan, nan, nan],
       [nan, nan, nan]])
Coordinates:
  * x        (x) int64 32B 20 10 29 39
  * y        (y) int64 24B 70 80 90
```

Filling missing values with manually specified values:

```pycon
>>> da1.reindex_like(da3, fill_value=19)
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 3,  4,  5],
       [ 0,  1,  2],
       [19, 19, 19],
       [19, 19, 19]])
Coordinates:
  * x        (x) int64 32B 20 10 29 39
  * y        (y) int64 24B 70 80 90
```

Note that unlike `broadcast_like`, `reindex_like` doesn’t create new dimensions:

```pycon
>>> da1.sel(x=20)
<xarray.DataArray (y: 3)> Size: 24B
array([3, 4, 5])
Coordinates:
  * y        (y) int64 24B 70 80 90
    x        int64 8B 20
```

…so `b` in not added here:

```pycon
>>> da1.sel(x=20).reindex_like(da1)
<xarray.DataArray (y: 3)> Size: 24B
array([3, 4, 5])
Coordinates:
  * y        (y) int64 24B 70 80 90
    x        int64 8B 20
```

<div id="7d02f469-529d-4ae0-8a00-e617ab877511" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('a7ea1cf9-989b-431d-aec1-892afcb2a91a','7d02f469-529d-4ae0-8a00-e617ab877511')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('a7ea1cf9-989b-431d-aec1-892afcb2a91a','7d02f469-529d-4ae0-8a00-e617ab877511')">Open In Tab</button></div><div id="4f9b93e1-ca11-4184-b24c-d75fa56a7dfa" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.reindex`](xarray.DataArray.reindex.html.md#xarray.DataArray.reindex), [`DataArray.broadcast_like`](xarray.DataArray.broadcast_like.html.md#xarray.DataArray.broadcast_like), [`align`](xarray.align.html.md#xarray.align)
