Get the positions of items of ser2 in ser1 as a list python 1

Get the positions of items of ser2 in ser1 as a list python

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

pos = []
for i in range(len(ser2)):
    for j in range(len(ser1)):
        if ser2[i] == ser1[j]:
            pos.append(j)

Here is what the above code is Doing:
1. Iterate over the elements of ser2
2. For each element in ser2, iterate over the elements of ser1
3. If the element of ser1 matches the element of ser2, append the index position of ser1 element
to the list pos

Similar Posts