Pandas DataFrame从时间戳获得计数号
我有一个数据帧,其中包含来自传感器的记录,列为 ['time', 'X', 'Y']。我知道传感器以15赫兹(固定频率)扫描,但每次扫描之间的时间间隔并不一致。数据帧包含有效的 X 和每当传感器扫描检测到物体时,每次扫描的 Y 位置记录及其相关时间戳。这意味着每当传感器未检测到物体时,数据中就会存在时间间隙。现在我想从该数据集中提取扫描编号,无论扫描结果是否有效。
这是我的数据框的示例:
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 |
这是预期的结果:
时间 | X | Y | 扫描编号 |
---|---|---|---|
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 |
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 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论