【发布时间】:2020-03-31 16:55:39
【问题描述】:
给定:两个数据帧的列=(id,时间戳),另一个数据帧列=(id,start_interval,end_interval),id 总是相同的。其中一个由 timetemp sec 组成,另一个只有时间戳间隔。
df_timestamp
id timestamp
1 11006 1365
2 11006 1366
3 11006 1367
4 11006 1368
5 11006 1369
...
101 11006 1465
102 11006 1466
103 11006 1467
104 11006 1468
...
df_intervals
id start_interval end_interval
1 11006 1250 1366
2 11006 1369 1455
...
12 11006 1466 1467
13 11006 1620 1950
...
任务:我需要创建新的数据框,其中 df_timestamp ['timestamp'] 值不在 df_intervals 'intervals' 值中或之间。
输出:
new_df
id timestamp
1 11006 1367
2 11006 1368
...
77 11006 1465
78 11006 1468
...
我尝试merge() 他们,但这个 dfs 非常大。也尝试添加一些逻辑表达式并失败。合并的情况似乎有效,但需要无限时间才能运行。此外,合并后需要合适的.loc。
有没有更优雅、更有效的方法来做到这一点?
【问题讨论】:
标签: python pandas merge timestamp intervals