Home > OS >  How could I handle the datetime for high frequency time series prediction (based on seconds)
How could I handle the datetime for high frequency time series prediction (based on seconds)

Time:01-03

I am a beginner for time series data analysis. How could I handle the datetime data for high frequency time series prediction (predict the value of next 2 seconds)?

I am working on time series data for predicting the value of next 2 seconds. The data time column is originally timestamp type and I have converted to datetime type with

pd.to_datetime(data.time,unit='us')

How could I change the followed date format to seconds for prediction? Any advice on model selection for high frequency time series prediction?

2020-01-12 15:12:20.354390   low
2020-01-12 15:12:20.354390    low
2020-01-12 15:12:20.500599    medium
2020-01-12 15:12:21.501825    high
2020-01-12 15:12:22.501052    .... 
2020-01-12 15:12:23.500284      
2020-01-12 15:12:24.501484    ...

CodePudding user response:

you can use Prophet for this purpose

df =pd.to_datetime(data.time,unit='us')

ad following

m = Prophet(changepoint_prior_scale=0.01).fit(df)
future = m.make_future_dataframe(periods=300, freq='H')
fcst = m.predict(future)
fig = m.plot(fcst)

hope see if it works

CodePudding user response:

Are you looking for:

df['time2'] = df['time'].to_numpy().astype(int)
print(df)

# Output
                        time                time2
0 2020-01-12 15:12:20.354390  1578841940354390000
1 2020-01-12 15:12:20.354390  1578841940354390000
2 2020-01-12 15:12:20.500599  1578841940500599000
3 2020-01-12 15:12:21.501825  1578841941501825000
4 2020-01-12 15:12:22.501052  1578841942501052000
5 2020-01-12 15:12:23.500284  1578841943500284000
6 2020-01-12 15:12:24.501484  1578841944501484000

CodePudding user response:

Coerce date to datetime, extract the time component and convert it to a timedelta element to get total seconds. Code below

df['seconds']=pd.to_timedelta(pd.to_datetime(df['datetime']).dt.strftime("%H:%M:%S.%f")).astype('timedelta64[s]')

      

    datetime                  seconds
0  2020-01-12 15:12:20.354390  54740.0
1  2020-01-12 15:12:20.354390  54740.0
2  2020-01-12 15:12:20.500599  54740.0
3  2020-01-12 15:12:21.501825  54741.0
4  2020-01-12 15:12:22.501052  54742.0
5  2020-01-12 15:12:23.500284  54743.0
6  2020-01-12 15:12:24.501484  54744.0
  • Related