import pandas as pd
import numpy as np
from geopy import distance
#Import all the files
shop_loc=pd.read_excel('locations.xlsx')
comp_loc=pd.read_excel('locations_comp.xlsx')
#convert the coordinates of both the files to a tuple list for the geopy to read the distance
shop_loc['coor']=list(zip(shop_loc.Lat,shop_loc.Lon))
comp_loc['coor']=list(zip(comp_loc.Long,comp_loc.Long))
#Function for the calculation of two points
def distance_from(loc1,loc2):
dis = distance.distance(loc1, loc2).miles
return round(dis,2)
#Calculate the distance of one shop location to competitor shop location
for _,row in comp_loc.iterrows():
shop_loc[row.Comp]=shop_loc['coor'].apply(lambda x: distance_from(row.coor,x))
I have 62 different shops and 8 different competitors in two different files. I am trying to find the distance of how far is each shop with all the 8 different competitors shop. When i do this individually for testing I get the correct locations. But as soon as i put this code out. I get very different distance values.
For instance Shop_location =(40.583639,-75.458446) Competitor_location = (40.049580,-75.086617) In the function i wrote i get almost more than 7900miles, However manually testing the distances gives me a distance of 41.75. Can anyone please help me in where I am going wrong