1 回答
TA贡献1796条经验 获得超4个赞
使用merge_asof
:
df = pd.merge_asof(df1,
df2,
left_index=True,
right_index=True,
tolerance=pd.Timedelta(24, 'H'),
direction='forward')
print (df)
A B
2019-12-02 1.000000 NaN
2019-12-04 1.020100 A
2019-12-05 1.030301 B
2019-12-06 1.040604 NaN
2019-12-09 1.051010 NaN
2019-12-10 1.061520 D
df = pd.merge_asof(df1,
df2,
left_index=True,
right_index=True,
tolerance=pd.Timedelta(25, 'H'),
direction='forward')
print (df)
A B
2019-12-02 1.000000 NaN
2019-12-04 1.020100 A
2019-12-05 1.030301 B
2019-12-06 1.040604 C
2019-12-09 1.051010 NaN
2019-12-10 1.061520 D
添加回答
举报