Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

calculate distance between latitude longitude columns for pandas data frame

I am trying to apply this code:

import h3

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)
distance = h3.point_dist(coords_1, coords_2, unit='km')
distance

to a pandas dataframe. This is my not working attempt.

data = {'lat1':[52.2296756],
        'long1':[21.0122287],
        'lat2':[52.406374],
        'long2':[16.9251681],      
}
df = pd.DataFrame(data)
df

df['distance'] = = h3.point_dist((df['lat1'], df['long1']), (df['lat2'], df['long2']), unit='km')

Any help would be very much appreciated. Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s working you need to just delete the second "="

data = {'lat1':[52.2296756],
        'long1':[21.0122287],
        'lat2':[52.406374],
        'long2':[16.9251681],      
}
df = pd.DataFrame(data)
df

df['distance'] =  h3.point_dist((df['lat1'], df['long1']), (df['lat2'], df['long2']), unit='km')

result

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading