当前位置: 首页 > 图灵资讯 > 行业资讯> 在Python中如何合并两个数据框

在Python中如何合并两个数据框

发布时间:2025-01-02 17:32:23

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

一个简单的解决方案是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(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

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

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09