How to use geophysical access distance across data columns?

I have a dataframe with a location column that contains lat, long location as follows

 deviceid                             location        
1102ADb75        [12.9404578177, 77.5548244743]

      

How do I get the distance between consecutive lines using the geife vicenty function? I have tried the following code

from geopy.distance import vincenty 
vincenty(df['location'].shift(-1), df['location']).miles

      

It returns the following error: TypeError: __new __ () takes at most 4 arguments (5 data)

EDIT - where df is a Pandas framework containing deviceId and Location columns as shown above Also

print type(df)
class 'pandas.core.frame.DataFrame'

      

+3


source to share


1 answer


Based on the gey github, you have to pass two tuples to the function vincenty

:

    >>> 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

      

+3


source







All Articles