title: Repeated calculation between consecutive rows of pandas dataframe
body: <p>I would like to calculate the distance along a path of GPS coordinates which are stored in two columns in a data frame.</p>
  
  <pre><code>import pandas as pd
  
  df = pd.DataFrame({ 'lat' : [1, 2.5, 3, 1.2],
                      'lng' : [1, 1, 2.1, 1],
                      'label': ['foo', 'bar', 'zip', 'foo']})
  print df
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>  label  lat  lng
  0   foo  1.0  1.0
  1   bar  2.5  1.0
  2   zip  3.0  2.1
  3   foo  1.2  1.0
  </code></pre>
  
  <p>The GPS coordinates are stored in radians.  So, the distance between the first and second rows of the dataframe can be calculated as follows:</p>
  
  <pre><code>import math as m
  
  r1 = 0
  r2 = 1
  
  distance =m.acos(m.sin(df.lat[r1]) * m.sin(df.lat[r2]) + 
       m.cos(df.lat[r1]) * m.cos(df.lat[r2]) * m.cos(df.lng[r2]-df.lng[r1]))*6371
  </code></pre>
  
  <p>I would like to repeat this calculation between every pair of consecutive rows and then add each short distance into the longer final distance for the full path.</p>
  
  <p>I could put this into a loop for n-1 rows of the dataframe, but is there a more pythonic way to do this?  </p>