Pandas
Pandas (28)
알 수 없는 사용자
2022. 8. 20. 21:54
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])