I have a Python dataframe with a continuous, but not equidistant index column and an associated timestamp. The index column corresponds to seconds since a device was switched on. The timestamp is implausible at the beginning and end of the data set.
My plan is to correct the timestamp: I determine the middle of the data set according the length of the dataframe and the corresponding timestamp. Based on this, I would now have to go back in time for all rows before the center and the timestamp determined there with the difference in the value from the index column and let all rows after the center progress in time accordingly. How can I solve this step back and forward in time?
the dataframe looks like this:
index datetime
2374.394 2021-07-08 08:58:36.8831974
2375.394 2021-07-08 08:58:36.8835716
2376.394 2021-07-08 08:58:36.8843326
2377.394 2021-07-08 08:58:36.9001954
2378.394 2021-07-08 08:58:36.9013572
...
5272.394 2021-07-08 09:46:54.0673135
5273.394 2021-07-08 09:46:55.0858515
5274.394 2021-07-08 09:46:57.1418275
5275.394 2021-07-08 09:46:57.1436671
5276.394 2021-07-08 09:46:58.1688952
...
10538.3936 2021-07-08 11:25:04.4640893
10539.3936 2021-07-08 11:25:04.4643238
10540.3936 2021-07-08 11:25:04.4645424
10541.3936 2021-07-08 11:25:04.4647257
10542.3936 2021-07-08 11:25:04.4649159
It can be downloaded from here:
dataset
I began to get the middle and its time stamp but how would I count the time backward and forward in a pythonian way according to the step difference of the index column?
# count rows, get the integer middle value)
mid_count = (len(df)//2)
# get index (seconds) and the time stamp
mid index = df.index[mid_count:mid_count+1]
mid_time = df.datetime[mid_count:mid_count+1]
print(mid_index)
print(mid_time)
For index and time stamp I get:
Int64Index([6458], dtype='int64', name='RadioRxTimePk')
RadioRxTimePk
6458 2021-07-08T10:06:37.1346374
Here I got stuck… or do you have a better way to correct the time column?