Write a Pandas program to get the positions of items of a given series in another given series
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]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer