简体   繁体   English

寻找时间序列的周期

[英]Finding periods of time series

I have a time series in a dataframe and i would like to find cases when signal "S" is significantly high and then low again.我在 dataframe 中有一个时间序列,我想找到信号“S”显着高然后又低的情况。

So i want to find 3 time periods A,B,C for which A: (s = average) -> B: (s = high -> C: (df[s] = average again). I have tried the following which finds n largest B moments for "S" and then tries to find periods before and after that B moment that satisfies the constraints:所以我想找到3个时间段A,B,C,其中A:(s =平均值)-> B:(s =高-> C:(df [s] =再次平均)。我尝试了以下找到 "S" 的 n 个最大 B 时刻,然后尝试找到满足约束的 B 时刻之前和之后的周期:

B = df.nlargest(3, 'S').index
threshold = 1
A = []
C = []
for b in B:
    A.append(min([i for i in df.index if (i < b) & (df['S'][i] <= df['S'][b] - threshold)], key=lambda x: abs(x - b)))
    C.append(min([i for i in df.index if (i > b) & (df['S'][i] <= df['S'][b] - threshold)], key=lambda x: abs(x - b)))

The problem is that get a ValueError: min() arg is an empty sequence error since there are not always A and C moments found.问题是得到一个ValueError: min() arg is an empty sequence错误,因为并不总是找到 A 和 C 时刻。 How can i solve this?我该如何解决这个问题? Can i use some kind of error handling and just print "No moments found"?我可以使用某种错误处理并仅打印“未找到时刻”吗? Or maybe a more clever method?或者也许是更聪明的方法? I would appreciate a lot some help我会很感激一些帮助

Thank you谢谢

example for df: df 的例子:

In [2]: df['S']
Out[2]: Date   Values
2019-01-06    194.021278
2019-02-03    196.034816
2019-03-03    193.071251
2019-03-31    190.647765
2019-04-28    190.791410
2019-05-26    190.465997
2019-06-23    192.097875
2019-07-21    192.704626
2019-08-18    193.757577
2019-09-15    193.480539
2019-10-13    193.800638
2019-11-10    192.289041
2019-12-08    195.755910
2020-01-05    198.654722
2020-02-02    199.804535
2020-03-01    198.191558

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM