python - Distance calculation in Geopy -
i using python 2.6.6 on centos 6.
have dataframe bringing in pickle file. i'd calculate distance between 2 points. have tried combine lat , long each point tuple , used geopy.great_circle. traceback includes this:
/opt/rh/python27/root/usr/lib/python2.7/site-packages/geopy/point.pyc in __new__(cls, latitude, longitude, altitude) 127 ) 128 else: --> 129 return cls.from_sequence(seq) 130 131 latitude = float(latitude or 0.0) /opt/rh/python27/root/usr/lib/python2.7/site-packages/geopy/point.pyc in from_sequence(cls, seq) 351 """ 352 args = tuple(islice(seq, 4)) --> 353 return cls(*args) 354 355 @classmethod typeerror: __new__() takes @ 4 arguments (5 given) my input pandas dataframe should of same length (if matters?)
import numpy np geopy.distance import vincenty import geopy import pandas pd distances_frame = pickle.load(open("distances.p", "rb")) samp = distances_frame.sample(n=50) samp = samp.dropna() point1 = tuple(zip(samp['biz_lat'],samp['biz_lon'])) point2 = tuple(zip(samp['id_lat'],samp['id_lon'])) dist= (vincenty(point1,point2).miles)
edit 'edchum' has correct answer in comments above..
samp.apply(lambda x: vincenty((x['biz_lat'],x['biz_lon']), (x['id_lat'], x['id_lon'])).miles, axis=1)
Comments
Post a Comment