La-Li-Lu-Le-Lo
La-Li-Lu-Le-Lo

Reputation: 101

How to get difference of two pandas indices, but only those of the first index?

I got two indices, Ix1 and Ix2.
I need the ones from Ix1, that are not in Ix2.

I only know

Ix1.difference(Ix2).intersection(Ix1)

But it doesn't work. I still get indices from Ix2, which aren't in Ix1. Ideas?

Upvotes: 1

Views: 57

Answers (1)

jezrael
jezrael

Reputation: 862761

Use first part only:

Ix1 = pd.Index([1,2,3,6,7])
Ix2 = pd.Index([0,1,2,4,5])

print (Ix1.difference(Ix2))
Int64Index([3, 6, 7], dtype='int64')

Upvotes: 1

Related Questions