'Calculating distance from centroid to another point in Python

I have a data frame like below

STORE_ID LATITUDE LONGITUDE GROUP
1        18.2738  28.38833  2
2        18.3849  28.29374  1
3        18.3948  28.29303  1
4        18.1949  28.28248  1        
5        18.2947  28.47392  1
6        18.7493  28.29475  2
7        18.4729  28.38392  3
8        18.1927  28.29485  2
9        18.2948  28.29384  1
10       18.1038  28.29489  3
11       18.7482  28.29374  1
12       18.9283  28.28484  2

And a second data frame like below

Tele_Booth_ID LATITUDE LONGITUDE
1             18.5638  28.19374  
2             18.2947  28.03727 
3             18.3849  28.26395 
4             18.9482  28.91847 

The first data frame has longitudes and latitudes of stores in a certain area. The store are grouped together into clusters represented by the GROUP field.

The second dataframe has longitudes and latitudes for telephone booths in that same area.

Using both these data frames I want to find the optimal locations to place more telephone booths.

If a store group has no telephone booths in the cluster or near the cluster, I would want to put a booth there. If a store group has a booth within the cluster, I would not want another booth there.

Using python how can I calculate the center point for each store group and then calculate the distance of each store group to the nearest booth?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source