问题描述
我有一个数据框,上面有两个不同的位置。我已经可以使用geolocator
和此old Stack Overflow Post找到他们的经度和纬度。现在,我一直在努力寻找这两列位置之间的距离。我一直在跟踪geodesic
向我们发送的this website's条信息。
目标是创建第五列,也是最后一列,向我显示位置之间的距离。我收到一条错误消息:
ValueError:从序列创建Point时,其项不得超过3个。
我创建的假数据集只有几个,但请注意我的真实数据集非常大,因此我需要在其中包含NaN的数千行中复制该数据集。待遇是一样的。该逻辑对于我必须如何创建此伪数据集可能没有任何意义,但会引发与原始数据集相同的错误。逻辑将我带到需要处理原始数据的地方,原始数据在两个位置值列中都具有更多唯一值。
places_data = pd.DataFrame(
{"Place_1": ["disneyland Park","Empire State Building","Yosemite Park","disney World Park","Rockefeller Tower","Grand Canyon"],"Places": ["Peaches","Apples","Peaches","Peaches"]}
)
other_places = places_data.copy()
other_places.loc[(other_places["Places"] == "Peaches"),"Sites"] = "Georgia Aquarium"
other_places.loc[(other_places["Places"] == "Apples"),"Sites"] = "World of Coca-Cola"
other_places["Loc_1"] = other_places["Place_1"].apply(geolocator.geocode).apply(lambda x: (x.latitude,x.longitude))
other_places["Loc_2"] = other_places["Sites"].apply(geolocator.geocode).apply(lambda x: (x.latitude,x.longitude))
places_data['Loc_1'] = places_data.Place_1.map(dict(other_places[['Place_1','Loc_1']].to_numpy()))
places_data['Loc_2'] = places_data.Places.map(dict(other_places[['Places','Loc_2']].to_numpy()))
places_data["distance"] = geodesic(places_data["Loc_1"],places_data["Loc_2"]).miles
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)