如何以最小间隔将未排序的时间序列数据切割成箱? [英] How to cut unsorted time-series data into bins with a minimum interval?

查看:24
本文介绍了如何以最小间隔将未排序的时间序列数据切割成箱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的数据框

<代码> X = pd.DataFrame({ 'A':[1.1341,1.13421,1.13433,1.13412,1.13435,1.13447,1.13459,1.13452,1.13471,1.1348,1.13496,1.13474,1.13483,1.1349,1.13502,1.13515,1.13526,1.13512]})

我们如何拆分这个系列以获得以下输出,使得最小差异至少为 0.0005

How can we split this series to get the following output such that the minimum difference is at least 0.0005

x['output'] =  [1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0]

推荐答案

我不相信有一种矢量化的方法可以做到这一点,因此您可能需要遍历这些值.

I don't believe there is a vectorized way to do this, so you probably need to loop through the values.

x = x.assign(output=0)  # Initialize all the output values to zero.
x['output'].iat[0] = 1
threshold = 0.0005
prior_val = x['a'].iat[0]
for n, val in enumerate(x['a']):
    if abs(val - prior_val) >= threshold:
        x['output'].iat[n] = 1
        prior_val = val  # Reset to new value found that exceeds threshold.

这篇关于如何以最小间隔将未排序的时间序列数据切割成箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆