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
Asked
Active
Viewed 136 times
-2
-
1use pandas.to_datetime – BloomShell Aug 23 '22 at 05:56
2 Answers
0
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.

jogepari
- 66
- 4
-
HI, Thanks for ur help, now could u please tell me how to replace this new coulmn with old one in TS – Aditya Bhandwalkar Aug 23 '22 at 07:02
-
You can just reassign column, like this: `df['TS'] = pd.to_datetime(df['TS']).astype('int64') // 10 ** 6`. – jogepari Aug 23 '22 at 07:10