我的主要数据框df
Id timestamp
265 2017-05-22 02:57:29
267 2017-05-22 04:35:18
279 2017-05-22 11:08:14
281 2017-05-22 11:39:39
282 2017-05-22 11:40:42
285 2017-05-22 11:52:48
288 2017-05-22 12:00:29
我的过滤器数据框df2
Id timestamp
283 2017-05-22 11:46:55
284 2017-05-22 11:51:41
286 2017-05-22 11:58:20
通常我会这样做
df[(df['timestamp'] >= '2017-05-22 11:46:55') & (df['dt'] =< '2017-05-22 11:58:20')]
但是,这不利于生产,并且可重复性较差
使用between
通过 df2
的 min
和 max
日期时间:
df3 = df[df['timestamp'].between(df2['timestamp'].min(), df2['timestamp'].max())]
print (df3)
Id timestamp
5 285 2017-05-22 11:52:48
我是一名优秀的程序员,十分优秀!