0

我在 Centos 6 上使用 Python 2.6.6。
我有一个dataframe从泡菜文件中引入的。然后我想计算2点之间的距离。我试图将每个点的latand组合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)
4

1 回答 1

2

编辑 'EdChum'在上面的评论中有正确的答案..

samp.apply(lambda x: vincenty((x['biz_lat'],x['biz_lon']), (x['id_lat'],   x['id_lon'])).miles, axis=1)
于 2016-01-06T15:37:43.333 回答