I have a dataframe with location column which contains lat,long location as follows
deviceid location
1102ADb75 [12.9404578177, 77.5548244743]
How to get the distance between consecutive rows using geopy's vicenty function? I tried following code
from geopy.distance import vincenty
vincenty(df['location'].shift(-1), df['location']).miles
It returns following error - TypeError: __new__() takes at most 4 arguments (5 given)
EDIT - where df is a Pandas dataframe containing deviceId & Location columns as shown above Also
print type(df)
class 'pandas.core.frame.DataFrame'
Based on geopy's github you should pass two tuples to the vincenty
function:
>>> from geopy.distance import vincenty
>>> point_a = (41.49008, -71.312796)
>>> point_b = (41.499498, -81.695391)
>>> print(vincenty(point_a, point_b).miles)
538.3904451566326
EDIT:
import pandas as pd
from geopy.distance import vincenty
data = [[101, [41.49008, -71.312796]],
[202, [41.499498, -81.695391]]]
df = pd.DataFrame(data=data, columns=['deviceid', 'location'])
print df
>>> deviceid location
>>> 0 101 [41.49008, -71.312796]
>>> 1 202 [41.499498, -81.695391]
print vincenty(df['location'][0], df['location'][1]).miles
>>> 538.390445157
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With