1 year ago
#384763
srad
Pandas Dataframe Getting Count number from Timestamps
I have a dataframe that contains recordings from a sensor with columns ['time', 'X', 'Y']. I know that the sensor scanned at 15 hz (fixed frequency), but the time interval between each scan is not consistent. The dataframe contains valid X & Y position recordings from each scan with their associated timestamp whenever the sensor scan detects an object. This means there are time gaps in the data whenever the sensor does not detect an object. Now I want to extract scan number from this data set irrespective of whether the scan resulted in a valid position or not.
Here is an example of my dataframe:
time | X | Y |
---|---|---|
2022-03-14 09:51:41.019000 | 12 | 4 |
2022-03-14 09:51:41.101000 | 12 | 5 |
2022-03-14 09:51:41.153000 | 13 | 6 |
2022-03-14 09:51:41.225000 | 15 | 6 |
2022-03-14 09:51:41.290000 | 16 | 5 |
2022-03-14 09:51:41.360000 | 16 | 5 |
2022-03-14 09:51:44.424000 | 26 | -3 |
2022-03-14 09:51:44.488000 | 28 | -4 |
2022-03-14 09:51:44.557000 | 29 | -4 |
And here is the expected outcome:
time | X | Y | Scan-number |
---|---|---|---|
2022-03-14 09:51:41.019000 | 12 | 4 | 1 |
2022-03-14 09:51:41.101000 | 12 | 5 | 2 |
2022-03-14 09:51:41.153000 | 13 | 6 | 3 |
2022-03-14 09:51:41.225000 | 15 | 6 | 4 |
2022-03-14 09:51:41.290000 | 16 | 5 | 5 |
2022-03-14 09:51:41.360000 | 16 | 5 | 6 |
2022-03-14 09:51:43.424000 | 26 | -3 | 37 |
2022-03-14 09:51:43.488000 | 28 | -4 | 38 |
2022-03-14 09:51:43.557000 | 29 | -4 | 39 |
pandas
timestamp
frame
0 Answers
Your Answer