# xarray.CFTimeIndex.sort_values

#### CFTimeIndex.sort_values(, return_indexer=False, ascending=True, na_position='last', key=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.14/site-packages/pandas/core/indexes/base.py#L5902-L5988)

Return a sorted copy of the index.

Return a sorted copy of the index, and optionally return the indices
that sorted the index itself.

* **Parameters:**
  * **return_indexer** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Should the indices that would sort the index be returned.
  * **ascending** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Should the index values be sorted in an ascending order.
  * **na_position** (`{'first' or 'last'}`, *default* `'last'`) – Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at
    the end.
  * **key** ([`callable()`](https://docs.python.org/3/builtins/functions.html#callable), *optional*) – If not None, apply the key function to the index values
    before sorting. This is similar to the key argument in the
    builtin `sorted()` function, with the notable difference that
    this key function should be *vectorized*. It should expect an
    `Index` and return an `Index` of the same shape.
* **Returns:**
  * **sorted_index** ([`pandas.Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index)) – Sorted copy of the index.
  * **indexer** ([`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), *optional*) – The indices that the index itself was sorted by.

#### SEE ALSO
`Series.sort_values`
: Sort values of a Series.

`DataFrame.sort_values`
: Sort values in a DataFrame.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('227466d4-57eb-4aee-a6aa-f54ceb427f90','60a6b000-6bba-4423-a51e-1e459eafb094','3bed6870-0649-411a-a7fb-fcd0e3112dbd','../lite/tree/../notebooks/index.html?path=9ccd38cb_d971_4264_942d_5fdf2c786209.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> idx = pd.Index([10, 100, 1, 1000])
>>> idx
Index([10, 100, 1, 1000], dtype='int64')
```

Sort values in ascending order (default behavior).

```pycon
>>> idx.sort_values()
Index([1, 10, 100, 1000], dtype='int64')
```

Sort values in descending order, and also get the indices idx was
sorted by.

```pycon
>>> idx.sort_values(ascending=False, return_indexer=True)
(Index([1000, 100, 10, 1], dtype='int64'), array([3, 1, 0, 2]))
```

<div id="3bed6870-0649-411a-a7fb-fcd0e3112dbd" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('227466d4-57eb-4aee-a6aa-f54ceb427f90','3bed6870-0649-411a-a7fb-fcd0e3112dbd')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('227466d4-57eb-4aee-a6aa-f54ceb427f90','3bed6870-0649-411a-a7fb-fcd0e3112dbd')">Open In Tab</button></div><div id="60a6b000-6bba-4423-a51e-1e459eafb094" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
