在Python中合并两个数据框的方法:
一个简单的解决方案是interval index
从start and end
设置中创建closed = both然后用于get_loc获取事件,即(希望所有日期时间都在timestamps dtype中)
df_2.index=pd.IntervalIndex.from_arrays(df_2['start'],df_2['end'],closed='both') df_1['event']=df_1['timestamp'].apply(lambdax:df_2.iloc[df_2.index.get_loc(x)]['event'])
输出:
时间戳AB事件 02016-05-1410:54:330.0202280.026572E1 12016-05-1410:54:340.0577800.175499E2 22016-05-1410:54:350.0988080.620986E2 32016-05-1410:54:360.1587891.014819E2 42016-05-1410:54:390.0381292.384590E3
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)