Search code examples
pythonpandasdataframeindices

Merging pandas dataframe indices


How can I merge 2 indices

index1
Out[8]: Int64Index([22, 23, 24, 25, 32, 33, 34], dtype='int64')

index2
Out[8]: Int64Index([20, 23, 24, 25, 32, 33, 34], dtype='int64')

so to obtain

index3
Out[8]: Int64Index([20, 22, 23, 24, 25, 32, 33, 34], dtype='int64')

that contains the index1 and index2 without duplicates?


Solution

  • Use union

    In [1331]: index1.union(index2)
    Out[1331]: Int64Index([20, 22, 23, 24, 25, 32, 33, 34], dtype='int64')