gpt4 book ai didi

python - 使用另一个时间戳数据帧来过滤 pandas 上的时间戳数据帧

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:33 25 4
gpt4 key购买 nike

我的主要数据框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通过 df2minmax 日期时间:

df3 = df[df['timestamp'].between(df2['timestamp'].min(), df2['timestamp'].max())]
print (df3)
Id timestamp
5 285 2017-05-22 11:52:48

关于python - 使用另一个时间戳数据帧来过滤 pandas 上的时间戳数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49622766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com