Home > Software engineering >  Shapelet discovery and transformation algorithm implementation
Shapelet discovery and transformation algorithm implementation

Time:08-24

I would like to know about any existing implementation(library , code) for shapelet discovery and transform in python to discover anomalies. for the following kind of data: enter image description here

CodePudding user response:

pandas.to_datetime(df["TS"], format="%Y-%m-%d %H:%M:%S.%f")

CodePudding user response:

Say this is your dataframe:

import pandas as pd
import datetime

df = pd.DataFrame({'TS': pd.date_range(
    start='2018-03-01 15:34:51.347340', periods=5, freq='100ms').astype(str)})
print(df)
print(type(df['TS'][0]))

#
                           TS
0  2018-03-01 15:34:51.347340
1  2018-03-01 15:34:51.447340
2  2018-03-01 15:34:51.547340
3  2018-03-01 15:34:51.647340
4  2018-03-01 15:34:51.747340
<class 'str'>

Straightforward method would be just using apply:

df['TS'].apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S.%f') \
            .timestamp() * 1000).astype('int64')

0    1519907691347
1    1519907691447
2    1519907691547
3    1519907691647
4    1519907691747
Name: TS, dtype: int64

Better approach, as described in this answer:

pd.to_datetime(df['TS']).astype('int64') // 10 ** 6

P.S. It's usually appropriate to provide your original data (column) created in code rather as a simple text, for responder's convenience.

  • Related