Index.union() joins two Index objects and sorts them , if possible. The following function behaves like a standard set union operation. The function can also find a union of categorical data.
Syntax: Index.union (other)
other: Index or array-like
Returns: union: Index
Example # 1: Use
Index.union () to find the union of two indexes.
# import pandas as pd
pandas as pd
# Create first index
# Create second index
# Print first index p >
# Print the second index
Let`s find the union of these two indices
The function found the concatenation of these two indices.
Example # 2: Use
Index.union () to perform a set join operation on the data of two indexes. Index marks are of string type.
Let`s find the union of these two indexes.
| tr > |
The function returned a new index that contains the result of the union of the idx1 and idx2 sets.