# xarray.CFTimeIndex.astype

#### CFTimeIndex.astype(dtype, copy=True)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.15/site-packages/pandas/core/indexes/base.py#L1149-L1216)

Create an Index with values cast to dtypes.

The class of a new Index is determined by dtype. When conversion is
impossible, a TypeError exception is raised.

* **Parameters:**
  * **dtype** (`numpy dtype` or `pandas type`) – Dtype for the result Index.
  * **copy** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`True`](https://docs.python.org/3/builtins/constants.html#True)) – By default, astype always returns a newly allocated object.
    If copy is set to False and internal requirements on dtype are
    satisfied, the original data is used to create a new Index
    or the original Index is returned.
* **Returns:**
  [`Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index) – Index with values cast to specified dtype.

#### SEE ALSO
`Index.dtype`
: Return the dtype object of the underlying data.

`Index.dtypes`
: Return the dtype object of the underlying data.

`Index.convert_dtypes`
: Convert columns to the best possible dtypes.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('496aa688-55fc-4ab3-942d-b4fbbcc030a1','fad716db-cd31-4dea-86a9-9d09627293f7','b8a2a4d9-5698-4dfc-9e7a-21b3282f6ec3','../lite/tree/../notebooks/index.html?path=b6cf6b7c_8cbb_4ac6_a038_61d36f92dbd6.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> idx = pd.Index([1, 2, 3])
>>> idx
Index([1, 2, 3], dtype='int64')
>>> idx.astype("float")
Index([1.0, 2.0, 3.0], dtype='float64')
```

<div id="b8a2a4d9-5698-4dfc-9e7a-21b3282f6ec3" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('496aa688-55fc-4ab3-942d-b4fbbcc030a1','b8a2a4d9-5698-4dfc-9e7a-21b3282f6ec3')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('496aa688-55fc-4ab3-942d-b4fbbcc030a1','b8a2a4d9-5698-4dfc-9e7a-21b3282f6ec3')">Open In Tab</button></div><div id="fad716db-cd31-4dea-86a9-9d09627293f7" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
