title: Finding the shortest distance between two points Python
body: <p>I have two dataframe. One contains <code>properties locations</code>, and the other contains <code>railway stations locations</code>.</p>
  
  <p>sample of properties dataframe(original Dataframe consist of ~700 rows):</p>
  
  <pre><code>properties=pd.DataFrame({'propertyID':['13425','32535','43255','52521'],
                   'lat':[-37.79230,-37.86400,-37.85450,-37.71870],
                  'lon':[145.10290,145.09720,145.02190,144.94330]})
  </code></pre>
  
  <p>sample of railway station dataframe(original Dataframe consist of ~90 rows):</p>
  
  <pre><code>stations=pd.DataFrame({'stationID':['11','33','21','34','22'],
                   'lat':[-37.416861,-37.703293,-37.729261,-37.777764,-37.579206],
                  'lon':[145.005372,144.572524,144.650631,144.772304,144.728165]})
  </code></pre>
  
  <p>I have a function to calculate the distance between two locations</p>
  
  <pre><code>from math import radians, cos, sin, asin, sqrt
  
  def haversine(lon1, lat1, lon2, lat2):
      """
      Calculate the great circle distance between two points 
      on the earth (specified in decimal degrees)
      """
      # convert decimal degrees to radians 
      lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
  
      # haversine formula 
      dlon = lon2 - lon1 
      dlat = lat2 - lat1 
      a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
      c = 2 * asin(sqrt(a)) 
      r = 6378 # Radius of earth in kilometers
      return c * r
  </code></pre>
  
  <p>I want to find the distance between each property and all stations. Then then pick the station with the shortest distance. </p>
  
  <p>I tried to construct a for loop but it doesn't return the shortest distance (min)</p>
  
  <pre><code>lst=[]
  for stopLat in stations['lat']:
      for stopLon in stations['lon']:
          for propLat in properties['lat']:
              for propLon in properties['lon']:
                  lst.append(haversine(propLon,propLat,stopLon,stopLat))
  </code></pre>
  
  <p>My final output would look like this. (Each property linked to the closest station).</p>
  
  <pre><code>stationID propertyID 
  11        52521
  33        13425
  21        32535
  34        43255      
  </code></pre>
  
  <p>Any advice on how to approach this would be helpful. Thanks </p>