Note
Pandas (16) 본문
728x90
How to get the positions of items of series A in another series B?
# Input
ser1 = pd.Series([10, 9, 6, 5, 3, 1, 12, 8, 13])
ser2 = pd.Series([1, 3, 10, 13])
# 1
[np.where(i == ser1)[0].tolist()[0] for i in ser2]
# 2
[pd.Index(ser1).get_loc(i) for i in ser2]
# output
[5, 4, 0, 8]
'Pandas' 카테고리의 다른 글
Pandas (18) (0) | 2022.08.09 |
---|---|
Pandas (17) (0) | 2022.08.08 |
Pandas (15) (0) | 2022.08.06 |
Pandas (14) (0) | 2022.08.05 |
Pandas (13) (0) | 2022.08.03 |
Comments