成都创新互联网站制作重庆分公司

创新互联Python教程:在Python中如何合并两个数据框

在Python中合并两个数据框的方法:

创新互联建站主营龙港网站建设的网络公司,主营网站建设方案,APP应用开发,龙港h5微信小程序定制开发搭建,龙港网站营销推广欢迎龙港等地区企业咨询

一个简单的解决方案是interval indexstart 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(lambda x : df_2.iloc[df_2.index.get_loc(x)]['event'])

输出:

            时间戳AB事件
0 2016-05-14 10:54:33 0.020228 0.026572 E1
1 2016-05-14 10:54:34 0.057780 0.175499 E2
2 2016-05-14 10:54:35 0.098808 0.620986 E2
3 2016-05-14 10:54:36 0.158789 1.014819 E2
4 2016-05-14 10:54:39 0.038129 2.384590 E3

更多相关学习推荐,敬请访问python教程栏目~


当前题目:创新互联Python教程:在Python中如何合并两个数据框
URL标题:http://cxhlcq.com/article/cccgied.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部