Note
Pandas (28) 본문
728x90
How to find all the local maxima (or peaks) in a numeric series?
# Input
ser = pd.Series([2, 10, 3, 4, 9, 10, 2, 7, 3])
# Solution
dd = np.diff(np.sign(np.diff(ser)))
peak_locs = np.where(dd == -2)[0] + 1
peak_locs
# output
array([1, 5, 7])
'Pandas' 카테고리의 다른 글
Pandas (30) (0) | 2022.08.22 |
---|---|
Pandas (29) (0) | 2022.08.21 |
Pandas (27) (0) | 2022.08.19 |
Pandas (26) (0) | 2022.08.17 |
Pandas (25) (0) | 2022.08.16 |
Comments