如何解决“ TypeError:必须是实数,而不是str”错误?

时间:2019-02-06 04:59:44

标签: python-3.x pandas pysal

我不断收到此错误。我的数据格式正确,但是我无法获取它来创建KDTree。

我有一个数据集,我们称它为A,另一个数据集,我们称它为B。这两个数据集都有许多纬度和经度坐标。我想看看在每个A的点的一定半径内有多少B的点。

欢迎所有帮助!

代码:

from pysal.cg.kdtree import KDTree
from pysal.cg import RADIUS_EARTH_MILES

trees_xys = results_df[['latitude', 'longitude']].values
trees_tree = KDTree(trees_xys, distance_metric='Arc', radius=RADIUS_EARTH_MILES)

错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-113-a46d6648d543> in <module>
      3 
      4 trees_xys = results_df[['latitude', 'longitude']].values
----> 5 trees_tree = KDTree(trees_xys, distance_metric='Arc', radius=RADIUS_EARTH_MILES)

~\Anaconda3\lib\site-packages\pysal\cg\kdtree.py in KDTree(data, leafsize, distance_metric, radius)
     54             return scipy.spatial.cKDTree(data, leafsize)
     55     elif distance_metric == 'Arc':
---> 56         return Arc_KDTree(data, leafsize, radius)
     57 
     58 

~\Anaconda3\lib\site-packages\pysal\cg\kdtree.py in __init__(self, data, leafsize, radius)
     88         self.radius = radius
     89         self.circumference = 2 * math.pi * radius
---> 90         temp_KDTree.__init__(self, list(map(sphere.toXYZ, data)), leafsize)
     91 
     92     def _toXYZ(self, x):

~\Anaconda3\lib\site-packages\pysal\cg\sphere.py in toXYZ(pt)
    110     x, y, z
    111     """
--> 112     phi, theta = list(map(math.radians, pt))
    113     phi, theta = phi + pi, theta + (pi / 2)
    114     x = 1 * sin(theta) * cos(phi)

TypeError: must be real number, not str

0 个答案:

没有答案