Given two pandas series find the position of elements in series2 in series1. you can assume that all elements in series2 will be present in

Given two pandas series, find the position of elements in series2 in series1. you can assume that all elements in series2 will be present in series1. the input will contain two lines with series1 and series2 respectively. the output should be a list of indexes indicating elements of series2 in series 1. note: in the output list, the indexes should be in ascending order.

Note: In the output list, the indexes should be in ascending order.

Sample Input:

[1,2,3,4,5,6,7]
[1,3,7]

Sample Output: [0,2,6]

Code:

import ast,sys
import pandas as pd

input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)

series1=pd.Series(input_list[0])
series2=pd.Series(input_list[1])

out_list=[pd.Index(series1).get_loc(num) for num in series2]
print(list(map(int,out_list)))

Comments