pyspark.pandas.Index.symmetric_difference#
- Index.symmetric_difference(other, result_name=None, sort=None)[source]#
Compute the symmetric difference of two Index objects.
- Parameters
- otherIndex or array-like
- result_namestr
- sortTrue or None, default None
Whether to sort the resulting index. * True : Attempt to sort the result. * None : Do not sort the result.
- Returns
- symmetric_differenceIndex
Notes
symmetric_difference
contains elements that appear in eitheridx1
oridx2
but not both. Equivalent to the Index created byidx1.difference(idx2) | idx2.difference(idx1)
with duplicates dropped.Examples
>>> s1 = ps.Series([1, 2, 3, 4], index=[1, 2, 3, 4]) >>> s2 = ps.Series([1, 2, 3, 4], index=[2, 3, 4, 5])
>>> s1.index.symmetric_difference(s2.index) Index([1, 5], dtype='int64')
You can set name of result Index.
>>> s1.index.symmetric_difference(s2.index, result_name='pandas-on-Spark') Index([1, 5], dtype='int64', name='pandas-on-Spark')
You can set sort to True, if you want to sort the resulting index.
>>> s1.index.symmetric_difference(s2.index, sort=True) Index([1, 5], dtype='int64')
You can also use the
^
operator:>>> (s1.index ^ s2.index) Index([1, 5], dtype='int64')