【发布时间】:2020-06-20 05:23:25
【问题描述】:
我有两个如下所示的数据框
df1
visit_counts SG_lat SG_long
0 3222.0 33.13623 -91.942026
1 6243.0 33.241981 -92.668384
2 5225.0 33.27683 -93.212498
3 6107.0 33.461784 -94.039191
4 3712.0 33.567683 -92.83685799999999
df2
num_transactions lat_dgr long_dgr
0 45433 35.293364 -93.716224
1 41172 35.293364 -93.716224
2 41909 35.293364 -93.716224
3 37979 35.293364 -93.716224
4 43546 35.293364 -93.716224
如果两个坐标之间的地理距离小于 100m,我想内连接这些数据框 像下面的伪代码 即
## pseudo code
coords_1 = (df1.SG_lat, df1.SG_long)
coords_2 = (df2.lat_dgr, df2.long_dgr)
geopy.distance.vincenty(coords_1, coords_2).m < 100
在 SQL 中,我们可以使用下面的 where 条件来做到这一点
ST_DISTANCE(ST_GEOGPOINT(long_dgr,lat_dgr), ST_GEOGPOINT( sg_long,sg_lat)) <= 100
pandas 合并函数不允许 where 条件。有没有其他方法可以加入这两个数据框。我没有任何其他键列要加入,然后使用 loc 进行过滤。
【问题讨论】:
-
你想计算所有可能的距离,还是只计算公共行/索引的距离?
-
@anon01 我想计算所有可能的距离,然后如果距离小于 100 则连接值,即我正在寻找距离
标签: python pandas dataframe pandas-groupby