pyspark.pandas.Index.union

Index.union(other: Union[pyspark.pandas.frame.DataFrame, pyspark.pandas.series.Series, Index, List], sort: Optional[bool] = None) → pyspark.pandas.indexes.base.Index

Form the union of two Index objects.

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

Whether to sort the resulting Index.

Returns
unionIndex

Examples

Index

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

MultiIndex

>>> midx1 = ps.MultiIndex.from_tuples([("x", "a"), ("x", "b"), ("x", "c"), ("x", "d")])
>>> midx2 = ps.MultiIndex.from_tuples([("x", "c"), ("x", "d"), ("x", "e"), ("x", "f")])
>>> midx1.union(midx2).sort_values()  
MultiIndex([('x', 'a'),
            ('x', 'b'),
            ('x', 'c'),
            ('x', 'd'),
            ('x', 'e'),
            ('x', 'f')],
           )