I have a set of timeseries data across a few different days. The data looks as follows. I would like to separate all the data into 2 seconds intervals and create a sliding window and then label each window with a label of "stay" or "leave". I tried using the pandas built-in windows but the window only lets me choose to have window size of integers (records in the dataframe), not time of 2 seconds etc.
Is making a sliding window necessary for this task? I looked online on how to do machine learning on time series data and it was mentioned that using windows is one of the basics of working with time series data.
Currently, I am thinking to generate all the 2 second intervals, and replicate each record (each record lasts from timestamp to timestamp of next record) according to the relevant timestamp in the original DataFrame to create a new DataFrame with records of 2 second intervals of the time series.
leave timeframe confidence restaurant timestamp event
0 false 2021-12-17T12:06:19+0800 to 2021-12-17T12:30:2... 2 Bistro NTT 2021-12-17 12:05:19+08:00 walking
1 false 2021-12-17T12:06:19+0800 to 2021-12-17T12:30:2... 2 Bistro NTT 2021-12-17 12:06:07+08:00 Previous activity ended. Recalculating activit...
2 false 2021-12-17T12:06:19+0800 to 2021-12-17T12:30:2... 2 Bistro NTT 2021-12-17 12:07:04+08:00 stationary
3 false 2021-12-17T12:06:19+0800 to 2021-12-17T12:30:2... 2 Bistro NTT 2021-12-17 12:08:35+08:00 Previous activity ended. Recalculating activit...
4 false 2021-12-17T12:06:19+0800 to 2021-12-17T12:30:2... 2 Bistro NTT 2021-12-17 12:08:47+08:00 stationary
as of now, I managed to create a dummy dataframe, all I need to do now is to fit my old dataframe onto the new dataframe. Basically, fit the graph into this new 2 second interval dataframe
rs = pd.date_range(start=timeseries.index[0], end=timeseries.index[-1], freq='2s') #index=timeseries.resample('2s').interpolate().iloc[1:].index
dummy_frame = pd.DataFrame(np.NaN, index=rs, columns=timeseries.columns)
dummy_frame.head()
output:
leave timeframe confidence restaurant event
2021-12-17 12:05:19+08:00 NaN NaN NaN NaN NaN
2021-12-17 12:05:21+08:00 NaN NaN NaN NaN NaN
2021-12-17 12:05:23+08:00 NaN NaN NaN NaN NaN
2021-12-17 12:05:25+08:00 NaN NaN NaN NaN NaN
2021-12-17 12:05:27+08:00 NaN NaN NaN NaN NaN
