Python 获取两个坐标之间的距离时出错

Python 获取两个坐标之间的距离时出错,python,pandas,dataframe,distance,haversine,Python,Pandas,Dataframe,Distance,Haversine,我有一个panda数据帧,具有以下模式: customer_id int64 vehicle_type object pickup_place object place_category object how_long_it_t

我有一个
panda数据帧
,具有以下
模式

customer_id                                     int64
vehicle_type                                   object
pickup_place                                   object
place_category                                 object
how_long_it_took_to_order                      object
pickup_lat                                    float64
pickup_lon                                    float64
dropoff_lat                                   float64
dropoff_lon                                   float64
pickup_coord                                   object
dropoff_coord                                  object
dtype: object
我正试图找到收货和卸货位置之间的距离。因此,我最初尝试使用哈弗森公式的方法。当我尝试使用

df_post['lat1'] = radians(df_post['pickup_lat'])
我得到了这个错误:

TypeError: cannot convert the series to <class 'float'>
但是当我尝试内置函数时

df_post['pickup_dropoff_distance']=gd.VincentyDistance(df_post['pickup_coord'],df_post['dropoff_coord']).miles
我收到一个新错误:

ValueError: When creating a Point from sequence, it must not have more than 3 items.

有人能帮我解释一下为什么会出现这两个错误,以及可能的解决方案是什么。

试试这个,它应该会起作用

df_post['lat1'] = radians(df_post['pickup_lat'].astype(float))

距离计算器的语法为
geopy.distance.VincentyDistance(coords_1,coords_2).miles
,其中
coords_1
coords_2
是元组

要将函数应用于数据帧中的每一行,需要使用:


是的,我在发布问题之前就这么做了,它不起作用
df_post['lat1'] = radians(df_post['pickup_lat'].astype(float))
def distancer(row):
    coords_1 = (row['pickup_lat'], row['pickup_long'])
    coords_2 = (row['dropoff_lat'], row['dropoff_long'])
    return geopy.distance.VincentyDistance(coords_1, coords_2).miles

df_post['pickup_dropoff_distance'] = df_post.apply(distancer, axis=1)