-1

I have a dataframe with columns "start lat", "start lon", "end lat" and "end lon". I want to use geopy to calculate distance for each row using above four columns. Plz help.

from geopy.distance import great_circle
great_circle([df['start station latitude'],
              df['start station longitude']],
             [df['end station latitude'],
              df['end station longitude']])
AbdealiLoKo
  • 3,261
  • 2
  • 20
  • 36
user2958481
  • 587
  • 2
  • 8
  • 20
  • figured it out... `df.apply(lambda x: great_circle((x['start station latitude'],x['start station longitude']), (x['end station latitude'], x['end station longitude'])).miles, axis=1)` – user2958481 Oct 31 '16 at 06:09

1 Answers1

2

Just converting your comment into an answer because I was trying to find the same thing and nearly missed it ...

df.apply(
    lambda x: great_circle(
        (x['start station latitude'], x['start station longitude']),
        (x['end station latitude'], x['end station longitude'])
    ).miles,
    axis=1)
AbdealiLoKo
  • 3,261
  • 2
  • 20
  • 36