pyspark.pandas.Index.difference#
- Index.difference(other, sort=None)[source]#
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) Index([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)], )