I have a pandas Dataframe df with these 4 colums :
And I want to create a new column with the distance between the pickup and the dropoff point.
I created this function :
def calcul_de_distance_vol_oiseau(data):
R = 6373.0
""" je change les variables en radians car python parle en radian et pas en degrées """
data['pickup_longitude'] = data['pickup_longitude'].apply(radians)
data['pickup_latitude'] = data['pickup_latitude'].apply(radians)
data['dropoff_longitude'] = data['dropoff_longitude'].apply(radians)
data['dropoff_latitude'] = data['dropoff_latitude'].apply(radians)
data['diff_lon'] = data['dropoff_longitude'] - data['pickup_longitude']
data['diff_lat'] = data['dropoff_latitude'] - data['dropoff_latitude']
data['calcul_intermediaire']= (data['diff_lat'] / 2).apply(sin)**2 + data['pickup_latitude'].apply(cos) * data['dropoff_latitude'].apply(cos) * (data['diff_lon'] / 2).apply(sin)**2
data['distance'] = R*np.arctan2((data['calcul_intermediaire']).apply(sqrt),(1 - data['calcul_intermediaire']).apply(sqrt))
return data
But when I want to verify the distance between my points, I don't have the same result as in this website https://www.sunearthtools.com/fr/tools/distance.php which calcul distance between gps points. I think there is a mathematical error in my function but I didn't find where.
Thanks in advance
I think you need only:
data['pickup_longitude'] = data['pickup_longitude'].apply(radians)
and similar code for the other columns (using lambda or defining a function).