Index.
symmetric_difference
Compute the symmetric difference of two Index objects.
Whether to sort the resulting index. * True : Attempt to sort the result. * None : Do not sort the result.
Notes
symmetric_difference contains elements that appear in either idx1 or idx2 but not both. Equivalent to the Index created by idx1.difference(idx2) | idx2.difference(idx1) with duplicates dropped.
idx1
idx2
idx1.difference(idx2) | idx2.difference(idx1)
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) Int64Index([5, 1], dtype='int64')
You can set name of result Index.
>>> s1.index.symmetric_difference(s2.index, result_name='pandas-on-Spark') Int64Index([5, 1], 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) Int64Index([1, 5], dtype='int64')
You can also use the ^ operator:
^
>>> s1.index ^ s2.index Int64Index([5, 1], dtype='int64')