pyspark.pandas.MultiIndex.difference

MultiIndex.difference(other: pyspark.pandas.indexes.base.Index, sort: Optional[bool] = None) → pyspark.pandas.indexes.base.Index

Return a new Index with elements from the index that are not in other.

This is the set difference of two Index objects.

Parameters
otherIndex or array-like
sortTrue or None, default None

Whether to sort the resulting index. * True : Attempt to sort the result. * None : Do not sort the result.

Returns
differenceIndex

Examples

>>> idx1 = ps.Index([2, 1, 3, 4])
>>> idx2 = ps.Index([3, 4, 5, 6])
>>> idx1.difference(idx2, sort=True)
Int64Index([1, 2], dtype='int64')

MultiIndex

>>> midx1 = ps.MultiIndex.from_tuples([('a', 'x', 1), ('b', 'y', 2), ('c', 'z', 3)])
>>> midx2 = ps.MultiIndex.from_tuples([('a', 'x', 1), ('b', 'z', 2), ('k', 'z', 3)])
>>> midx1.difference(midx2)  
MultiIndex([('b', 'y', 2),
            ('c', 'z', 3)],
           )