# 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('cdef291f-dcea-43da-8135-dad93bfba17f','a7dfa3d6-288e-41d4-bb69-b39e093f5bdb','672ac987-9781-445a-a5b3-d3bb55ced905','../lite/tree/../notebooks/index.html?path=5666c264_edb7_47da_91c0_9f76748970a4.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="672ac987-9781-445a-a5b3-d3bb55ced905" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('cdef291f-dcea-43da-8135-dad93bfba17f','672ac987-9781-445a-a5b3-d3bb55ced905')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('cdef291f-dcea-43da-8135-dad93bfba17f','672ac987-9781-445a-a5b3-d3bb55ced905')">Open In Tab</button></div><div id="a7dfa3d6-288e-41d4-bb69-b39e093f5bdb" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
