# xarray.CFTimeIndex.difference

#### CFTimeIndex.difference(other, sort=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.14/site-packages/pandas/core/indexes/base.py#L3400-L3470)

Return a new Index with elements of index not in other.

This is the set difference of two Index objects.

* **Parameters:**
  * **other** ([`Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Index object or an array-like object containing elements to be compared
    with the elements of the original Index.
  * **sort** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *default* [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Whether to sort the resulting index. By default, the
    values are attempted to be sorted, but any TypeError from
    incomparable elements is caught by pandas.
    * None : Attempt to sort the result, but catch any TypeErrors
      from comparing incomparable elements.
    * False : Do not sort the result.
    * True : Sort the result (which may raise TypeError).
* **Returns:**
  [`Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index) – Returns a new Index object containing elements that are in the original
  Index but not in the other Index.

#### SEE ALSO
`Index.symmetric_difference`
: Compute the symmetric difference of two Index objects.

`Index.intersection`
: Form the intersection of two Index objects.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('b0ffa175-e042-47d6-b568-8a9d76ef921e','31a957f6-c235-4106-b743-0804f3d7338a','8ee0909a-7e51-4044-a812-a9cff2485732','../lite/tree/../notebooks/index.html?path=e9114b22_8560_4c22_99b2_ba687d44adcf.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> idx1 = pd.Index([2, 1, 3, 4])
>>> idx2 = pd.Index([3, 4, 5, 6])
>>> idx1.difference(idx2)
Index([1, 2], dtype='int64')
>>> idx1.difference(idx2, sort=False)
Index([2, 1], dtype='int64')
```

<div id="8ee0909a-7e51-4044-a812-a9cff2485732" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('b0ffa175-e042-47d6-b568-8a9d76ef921e','8ee0909a-7e51-4044-a812-a9cff2485732')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('b0ffa175-e042-47d6-b568-8a9d76ef921e','8ee0909a-7e51-4044-a812-a9cff2485732')">Open In Tab</button></div><div id="31a957f6-c235-4106-b743-0804f3d7338a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
