Q:

Write a Pandas program to get the positions of items of a given series in another given series

0

Write a Pandas program to get the positions of items of a given series in another given series

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import pandas as pd
series1 = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
series2 = pd.Series([1, 3, 5, 7, 10])
print("Original Series:")
print(series1)
print(series2)
result = [pd.Index(series1).get_loc(i) for i in series2]
print("Positions of items of series2 in series1:")
print(result)

Sample Output:

Original Series:
0     1
1     2
2     3
3     4
4     5
5     6
6     7
7     8
8     9
9    10
dtype: int64
0     1
1     3
2     5
3     7
4    10
dtype: int64
Positions of items of series2 in series1:
[0, 2, 4, 6, 9]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now