# xarray.CFTimeIndex.asof

#### CFTimeIndex.asof(label)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.14/site-packages/pandas/core/indexes/base.py#L5730-L5803)

Return the label from the index, or, if not present, the previous one.

Assuming that the index is sorted, return the passed index label if it
is in the index, or return the previous index label if the passed one
is not in the index.

* **Parameters:**
  **label** ([`object`](https://docs.python.org/3/builtins/functions.html#object)) – The label up to which the method returns the latest index label.
* **Returns:**
  [`object`](https://docs.python.org/3/builtins/functions.html#object) – The passed label if it is in the index. The previous label if the
  passed label is not in the sorted index or NaN if there is no
  such label.

#### SEE ALSO
`Series.asof`
: Return the latest value in a Series up to the passed index.

`merge_asof`
: Perform an asof merge (similar to left join but it matches on nearest key rather than equal key).

`Index.get_loc`
: An asof is a thin wrapper around get_loc with method=’pad’.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('29612630-02f0-4144-bc1e-7502b097f9a6','6b4035a3-211f-4c93-b1dc-c70a36eeda40','badee200-cc1e-40fa-9244-e03014fde2a8','../lite/tree/../notebooks/index.html?path=3fdd41c9_0d9f_4cc4_be73_d42d22388c5e.ipynb','None')">Try it in your browser!</button></div>

Index.asof returns the latest index label up to the passed label.

```pycon
>>> idx = pd.Index(["2013-12-31", "2014-01-02", "2014-01-03"])
>>> idx.asof("2014-01-01")
'2013-12-31'
```

If the label is in the index, the method returns the passed label.

```pycon
>>> idx.asof("2014-01-02")
'2014-01-02'
```

If all of the labels in the index are later than the passed label,
NaN is returned.

```pycon
>>> idx.asof("1999-01-02")
nan
```

If the index is not sorted, an error is raised.

```pycon
>>> idx_not_sorted = pd.Index(["2013-12-31", "2015-01-02", "2014-01-03"])
>>> idx_not_sorted.asof("2013-12-31")
Traceback (most recent call last):
ValueError: index must be monotonic increasing or decreasing
```

<div id="badee200-cc1e-40fa-9244-e03014fde2a8" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('29612630-02f0-4144-bc1e-7502b097f9a6','badee200-cc1e-40fa-9244-e03014fde2a8')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('29612630-02f0-4144-bc1e-7502b097f9a6','badee200-cc1e-40fa-9244-e03014fde2a8')">Open In Tab</button></div><div id="6b4035a3-211f-4c93-b1dc-c70a36eeda40" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
