如何检测和过滤时间序列数据的峰值?

2024-04-30 05:02:31 发布

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

我有一个pandas用户登录数据框,如下所示:

    id     datetime_login 
    646  2017-03-15 15:30:25
    611  2017-04-14 11:38:30
    611  2017-05-15 08:49:01
    651  2017-03-15 15:30:25
    611  2017-03-15 15:30:25
    652  2017-03-08 14:03:56
    652  2017-03-08 14:03:56
    652  2017-03-15 15:30:25
    654  2017-03-15 15:30:25
    649  2017-03-15 15:30:25
    902  2017-09-09 15:00:00
    902  2017-02-13 16:39:53
    902  2017-11-15 12:00:00
    902  2017-11-15 12:00:00
    902  2017-09-09 15:00:00
    902  2017-05-15 08:48:47
    902  2017-11-15 12:00:00

绘制登录信息后:

^{pr2}$
  1. 如何在曲线图中检测时间序列数据的峰值?

  2. 如何将时间序列数据中的峰值过滤到数组中?

我试着:

^{3}$

但是,我得到了:

TypeError: unsupported operand type(s) for -: 'datetime.date' and 'int'

但是,我得到了:


Tags: 数据用户信息idpandasdatetime时间绘制
1条回答
网友
1楼 · 发布于 2024-04-30 05:02:31

在哪里 df.datetime_login.value_counts().sort_index().plot(figsize=(25,10), colormap='jet',fontsize=20)绘图:

enter image description here

让我们试试下面的方法,您需要使用value_counts返回的序列,而不是原来的df peakutils.indexes

df_counts = df.datetime_login.value_counts().sort_index()
df_counts[peakutils.indexes(df_counts, thres=0.4, min_dist=1000)]

输出:

^{pr2}$

相关问题 更多 >