# xarray.CFTimeIndex.difference

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

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('701fb4c6-7925-40b5-b6a6-1d1fd5989c8f','3ce14fd7-9ac8-4a9d-b935-3ae73dfed7d9','5a44ff86-96a9-4c97-9d79-13b30514a387','../lite/tree/../notebooks/index.html?path=5a91cc4a_b4d6_4cf7_a227_136891fd7b4d.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="5a44ff86-96a9-4c97-9d79-13b30514a387" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('701fb4c6-7925-40b5-b6a6-1d1fd5989c8f','5a44ff86-96a9-4c97-9d79-13b30514a387')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('701fb4c6-7925-40b5-b6a6-1d1fd5989c8f','5a44ff86-96a9-4c97-9d79-13b30514a387')">Open In Tab</button></div><div id="3ce14fd7-9ac8-4a9d-b935-3ae73dfed7d9" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
