Get index of one series into another in pandas

I have two series, and I want to get the index of each value of one series into the other:

import pandas as pd

s1 = pd.Series(list('ABCDE'), index=range(1, 6))
s2 = pd.Series(list('BDAACE'))
expected_result = pd.Series([2, 4, 1, 1, 3, 5])

assert pd.some_operation(s1, s2).equals(expected_result)

I know it sounds simple but I haven't been able to find a way to do it in a vectorized way.

Upvotes: 2

Views: 61

Answers (1)

BENY
BENY

Reputation: 323226

Using Series get

pd.Series(s1.index,index=s1).get(s2)
Out[416]: 
B    2
D    4
A    1
A    1
C    3
E    5
dtype: int64

Upvotes: 3

Related Questions