I have a pandas dataframe my_df
with the following columns :
id lat1 lon1 lat2 lon2
1 45 0 41 3
2 40 1 42 4
3 42 2 37 1
Basically, I'd like to do the following :
import haversine
haversine.haversine((45, 0), (41, 3)) # just to show syntax of haversine()
> 507.20410687342115
# what I'd like to do
my_df["dist"] = haversine.haversine((my_df["lat1"], my_df["lon1"]),(my_df["lat2"], my_df["lon2"]))
TypeError: cannot convert the series to < class 'float' >
Using this, I tried the following :
my_df['dist'] = haversine.haversine(
list(zip(*[my_df[['lat1','lon1']][c].values.tolist() for c in my_df[['lat1','lon1']]]))
,
list(zip(*[my_df[['lat2','lon2']][c].values.tolist() for c in my_df[['lat2','lon2']]]))
)
File "blabla\lib\site-packages\haversine__init__.py", line 20, in haversine lat1, lng1 = point1
ValueError: too many values to unpack (expected 2)
Any idea of what I'm doing wrong / how I can achieve what I want ?