Pandas

Pandas (16)

Jun's N 2022. 8. 7. 19:22

How to get the positions of items of series A in another series B?

# Input
ser1 = pd.Series([10, 9, 6, 5, 3, 1, 12, 8, 13])
ser2 = pd.Series([1, 3, 10, 13])

# 1
[np.where(i == ser1)[0].tolist()[0] for i in ser2]

# 2
[pd.Index(ser1).get_loc(i) for i in ser2]

# output
[5, 4, 0, 8]
728x90