Pandas:查找高于定义阈值的末端频谱

2024-10-05 10:01:34 发布

您现在位置:Python中文网/ 问答频道 /正文

长期读者,第一次发布

我正在处理熊猫数据帧中频率响应图的x,y数据。以下是数据和绘图的示例(请参阅本文末尾的完整.csv文件):

fbc['x'],fbc['y']

(0    [89.25, 89.543, 89.719, 90.217, 90.422, 90.686...
 1    [89.25, 89.602, 90.422, 90.568, 90.744, 91.242...
 2    [89.25, 89.689, 89.895, 90.305, 91.008, 91.74,...
 3    [89.25, 89.514, 90.041, 90.275, 90.422, 90.832...
 Name: x, dtype: object,
 0    [-77.775, -77.869, -77.766, -76.572, -76.327, ...
 1    [-70.036, -70.223, -71.19, -71.229, -70.918, -...
 2    [-73.079, -73.354, -73.317, -72.753, -72.061, ...
 3    [-70.854, -71.377, -74.069, -74.712, -74.647, ...
 Name: y, dtype: object)

其中x=频率,y=振幅数据。每种情况的结果图如下所示:

See x,y Plot of image in this link - not enough points to embed yet

我可以为数据框中的每一行x,y数据创建一个绘图

在Pandas(Python)中,我需要做的是在频率响应下降到噪声地板(永久性)之前确定数据中的最高频率。如您所见,在某些地方,y数据可能会变为非常低的值(例如<;-50),但随后会返回到>;-40.

我如何在Pandas/python中进行检测(由于数据量非常大,理想情况下不需要迭代)以找到最高频率(>;-40),这样我就知道频率不会回到<-再跳40,然后再跳回来基本上,我试图找到频带的末端。我曾尝试使用一些熊猫的统计数据(这也很好),但未能获得有用的数据

提前感谢您提供的任何指示和方向

下面是一个.csv文件,可以使用csv.reader导入:https://www.dropbox.com/s/ia7icov5fwh3h6j/sample_data.csv?dl=0


Tags: 文件csv数据nameltgt绘图pandas
1条回答
网友
1楼 · 发布于 2024-10-05 10:01:34

我相信我已经想出了一个解决办法:

根据@katardin的建议,我提出了以下建议,尽管我认为可以优化。同样,我将处理大量数据,因此,如果有人能找到更优雅的解决方案,我将不胜感激

for row in fbc['y']:
    list_reverse = row

    # Reverse y data so we read from end (right to left)
    test_list = list_reverse[::-1]

    # Find value of y data above noise floor (>-50)
    res = next(x for x, val in enumerate(test_list) if val > -50) 

    # Since we reversed the y data we must take the opposite of the returned res to 
    # get the correct index
    index = len(test_list) - res

    # Print results
    print ("The index of element is : " + str(index))

其中,输出为索引编号,如下所示:

The index of element is : 2460
The index of element is : 2400
The index of element is : 2398
The index of element is : 2382

我检查过的每一个都对应于我一直在寻找的精确的高频衰减点。好建议

相关问题 更多 >

    热门问题