【发布时间】:2021-08-22 09:37:58
【问题描述】:
我有以下系列并试图找到应该是[1,8.5] 的峰值索引或应该是[279,139] 的峰值。使用的阈值为 100。我尝试了很多方法,但它总是忽略系列索引并返回 [1,16]。
0.5 0
1.0 279
1.5 256
2.0 84
2.5 23
3.0 11
3.5 3
4.0 2
4.5 7
5.0 5
5.5 4
6.0 4
6.5 10
7.0 30
7.5 88
8.0 133
8.5 139
9.0 84
9.5 55
10.0 26
10.5 10
11.0 8
11.5 4
12.0 4
12.5 1
13.0 0
13.5 0
14.0 1
14.5 0
我试过这段代码
thresh = 100
peak_idx, _ = find_peaks(out.value_counts(sort=False), height=thresh)
plt.plot(out.value_counts(sort=False).index[peak_idx], out.value_counts(sort=False)[peak_idx], 'r.')
out.value_counts(sort=False).plot.bar()
plt.show()
peak_idx
这是输出
array([ 1, 16], dtype=int64)
【问题讨论】:
-
代码没问题,如果你检查它确实找到了正确的峰值,那么你在图表中绘制点的方式有问题
-
您误解了 find_peaks 的工作原理,它确实返回峰的索引而不是峰的值
标签: python pandas dataframe series peak-detection