【问题标题】:Is there a way to classify data points with python above a value and series threshold (consecutive numbers above the threshold)?有没有办法用 python 对高于值和系列阈值(连续数字高于阈值)的数据点进行分类?
【发布时间】:2021-11-21 16:18:16
【问题描述】:

我正在尝试使用 python 对数据进行分类,首先建立一个阈值,然后在一段时间内高于阈值时对其进行分类。

示例数据:我的值阈值>4,我的系列阈值>2

[5,5,1,1,1,5,5,5,4,4,4,4,5,5,5,5,5] 

预期输出:注意前两个值为零,因为它们不符合系列阈值

[0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1]

所以,我只想在数据同时满足系列和值阈值时将数据分类为1。

有谁知道用 python 附加这个问题的最佳方法吗?

【问题讨论】:

  • 按照您的指示,我得到了不同的结果。我得到[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1]。例如,最后五个值,只有最后三个值通过了两个测试,因为对于前两个值,系列测试只找到一个或两个通过值检查的值。要么示例是错误的,要么我误解了您的指示。

标签: python pandas dataframe signal-processing threshold


【解决方案1】:

IIUC,您可以按以下方式使用numpy

import numpy as np

a = np.array([5,5,1,1,1,5,5,5,4,4,4,4,5,5,5,5,5])
v_threshold = 4
s_threshold = 2

out = np.zeros_like(a)

out[s_threshold:] = a[s_threshold:] > v_threshold
#array([0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 2015-05-09
    • 1970-01-01
    • 2021-02-26
    相关资源
    最近更新 更多