I am trying to convert a function to a more optimized way in order to reduce the computation time. More specifically, I want to keep the minimum haversine distance for each point of plot1 compared to all points of plot2 (where plot1, plot2 dataframes with latitude, longitude columns). Here is my code:
def calculate_min_haversine_distance(plot1, plot2):
for index,row in plot1.iterrows():
minimum = 100000000
for index2, row2 in plot2.iterrows():
dis = haversine_distance(row.latitude, row.longitude, row2.latitude, row2.longitude)
if (dis<minimum):
minimum=dis
plot1.loc(index,'Min Haversine Distance') = minimum
return plot1