Как обнаружить и отфильтровать пики данных временных рядов? - PullRequest
0 голосов
/ 25 июня 2018

У меня есть pandas dataframe пользовательских логинов, подобных этому:

    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

После построения логинов:

df.datetime_login = df.datetime_login.apply(lambda x: str(x)[:10])
df.datetime_login = df.datetime_login.apply(lambda x: date(int(x[:4]), int(x[5:7]), int(x[8:10])))


fig, ax = subplots()
df.datetime_login.value_counts().sort_index().plot(figsize=(25,10), colormap='jet',fontsize=20)
  1. Как я могу обнаружить на своем графике пики в данных временных рядов?

  2. Как я могу отфильтровать в массив пики в моих данных временных рядов?

Я пытался:

import peakutils
indices = peakutils.indexes(df, thres=0.4, min_dist=1000)
print(indices) 

Однако я получил:

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

Однако я получил:

1 Ответ

0 голосов
/ 25 июня 2018

Где 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)]

Выход:

2017-03-15 15:30:25    6
Name: datetime_login, dtype: int64
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...