我在Centos 6上使用Python 2.6.6
我有一个来自pickle文件的dataframe
。然后我想计算2点之间的距离。我尝试将每个点的lat
和long
合并为一个元组,然后使用Geopy.great_circle
。然而,追溯包括:
/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 at most 4 arguments (5 given)
我的输入来自Pandas DataFrame,它应该具有相同的长度(如果重要的话?)
import numpy as np
from geopy.distance import vincenty
import geopy
import pandas as 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)
答案 0 :(得分:2)
编辑' EdChum'在上面的评论中有正确的答案..
samp.apply(lambda x: vincenty((x['biz_lat'],x['biz_lon']), (x['id_lat'], x['id_lon'])).miles, axis=1)