Write a Pandas program to get the positions of items of a given series in another given series
- برمجة بايثون
- 2021-09-10
- mhanasmh00489829403
الأجوبة
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]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال