简体   繁体   English

使用非 integer 索引在 pandas 系列中查找峰值

[英]Finding peaks in pandas series with non integer index

I have the following series and trying to find the index of the peaks which should be [1,8.5] or the peak value which should be [279,139] .我有以下系列,并试图找到应该是 [1,8.5] 的峰值索引或应该是[279,139] [1,8.5]的峰值。 the used threshold is 100. I tried many ways but, it always ignores the series index and returns [1,16] .使用的阈值为 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

I tried this code我试过这段代码

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

here is the output array([ 1, 16], dtype=int64)这是 output array([ 1, 16], dtype=int64)

在此处输入图像描述

You are doing it right the only thing that you misunderstood is that find_peaks finds the indexes of the peaks, not peaks themselves.你做对了,你唯一误解的是find_peaks找到了峰的索引,而不是峰本身。

Here is the documentation that clearly states that:这是明确指出的文档:

Returns

peaksndarray

    Indices of peaks in x that satisfy all given conditions.

Reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks.html参考资料: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.find_peaks.html

Try this code here:在此处尝试此代码:

thresh = 100
y = [0,279,256, 84, 23, 11,  3,  2,  7,  5,  4,  4, 10, 30, 88,133,139, 84, 55, 26, 10,  8,  4,  4,  1,  0,  0,  1,  0]
x = [0.5 ,1.0 ,1.5 ,2.0 ,2.5 ,3.0 ,3.5 ,4.0 ,4.5 ,5.0 ,5.5 ,6.0 ,6.5 ,7.0 ,7.5 ,8.0 ,8.5 ,9.0 ,9.5 ,10.0,10.5,11.0,11.5,12.0,12.5,13.0,13.5,14.0,14.5]
peak_idx, _ = find_peaks(x, height=thresh)
out_values = [x[peak] for peak in peak_idx]

Here out_vaules will contain what you want这里 out_vaules 将包含你想要的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 按索引名称、整数索引拆分熊猫系列 - Split pandas series by index names, integer index 查找熊猫系列中的第一个非零值 - Finding the first non zero value in a Pandas Series 通过 integer 索引选择一行 pandas 系列/数据帧 - Selecting a row of pandas series/dataframe by integer index 用python查找正弦数值序列的峰 - Finding peaks of a sine numerical series with python 使用整数索引重新采样熊猫系列(添加缺失索引) - Resampling Pandas Series with integer index (add missing index) Python Pandas:使用数组值查找熊猫系列的索引 - Python Pandas: Finding the index of a pandas series with an array value 得到非数字索引之后的所有内容,不包括熊猫系列中的索引 - get everything after non numeric index not including the index in a pandas series 使用 numpy 和 pandas 在数字序列中查找局部最大值或峰值(索引) 峰值指的是两侧被较小值包围的值 - Find local maxima or peaks(index) in a numeric series using numpy and pandas Peak refers to the values surrounded by smaller values on both sides 在没有迭代的情况下在Pandas系列中查找连续的,非唯一的切片 - Finding contiguous, non-unique slices in Pandas series without iterating 通过具有整数索引的已排序熊猫系列中的位置访问值 - Access value by location in sorted pandas series with integer index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM