”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 如何根据时间戳范围加入数据范围?

如何根据时间戳范围加入数据范围?

发布于2025-03-22
浏览:169

[

How to Join DataFrames Based on Timestamp Ranges?
基于列值ranges

实现这一目标的一种方法是从df_2中的开始和末端列创建一个间隔索引。然后,我们可以使用get_loc方法获得DF_1中每个时间戳的相应事件。这是此解决方案的python代码:

#从df_2创建间隔索引 df_2.index = pd.intervalindex.from_arrays(df_2 ['start'],df_2 ['end'],nluct ='ot ='两者') #获取DF_1中每个时间戳的相应事件 df_1 ['event'] = df_1 ['timestamp']。应用(lambda x:df_2.iloc [df_2.index.get_loc(x)] ['event''])在DF_1中命名为DF_1中的新列,其中包含每个符号事件的df_1,该事件为每个fimestamp shiles of Seppefs seppecied sefters necters necters necters nects nects necters necters nectife nectife the nectement。生成的加入数据框将包含以下列: TIMESTAMP A B事件

最新教程 更多>

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3