ID timestamp lat lon
0 A 2020-03-20 00:17:10 42.360000 -71.090000
1 A 2020-03-20 00:20:51 42.360000 -71.090000
2 A 2020-03-20 00:35:31 42.360000 -71.090000
3 A 2020-03-20 00:35:34 42.360000 -71.090000
4 B 2020-03-20 01:48:14 42.360000 -71.100000
5 B 2020-03-20 03:15:00 42.360000 -71.100000
6 C 2020-03-20 11:05:47 42.365259 -71.103502
7 D 2020-03-20 10:53:43 42.363174 -71.096756
8 D 2020-03-20 10:57:45 42.363260 -71.095598
9 D 2020-03-20 11:04:24 42.363303 -71.094997
我想看看两个用户之间是否在100
米的半径范围内,在白天的任何时间至少10
秒有重叠。我希望有如下输出
df
usuerI userJ centroid.lat centroid.lon time
0 A B 42.360000 -71.094997 33s
1 B D 42.365259 -71.103502 5s
我不知道你尝试了什么,但你可以这样开始。 我没有考虑10秒的计时,但很容易添加。我使用
geopy.distance.distance
来测量距离。下面的代码将这些遭遇存储在一个列表中,您可以从中轻松构建一个新的数据帧对于本例,我添加了一些额外的行,以使数据工作得更好。值得注意的是,这种方法需要大量的优化和错误处理才能很好地扩展
接下来我们需要稍微调整一下df
然后我们找到距离阈值内的点。距离_thresh_列表存储列表列表,其中子列表包含每组距离小于~100m的点的idx值
然后我们寻找唯一的ID
最后,我们寻找时间匹配
以下是匹配项(有重复项)
因此,上面的代码只查看ID在一段时间内是否彼此靠近。如果我们想计算ID彼此靠近的时间,我们可以这样做
一旦我们有了存储时间范围的dict,我们就可以看到同一位置的id之间有多少共享秒
因此,时间/位置交叉点如下所示。FWIW,如果没有更多的样本数据行,这不是很令人兴奋,而且这种方法需要额外的复杂性才能处理2个以上的唯一ID
相关问题 更多 >
编程相关推荐