Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 计算一组位置和特定点之间最小距离的最快方法(数据帧)_Python_Pandas_Performance_Geopy - Fatal编程技术网

Python 计算一组位置和特定点之间最小距离的最快方法(数据帧)

Python 计算一组位置和特定点之间最小距离的最快方法(数据帧),python,pandas,performance,geopy,Python,Pandas,Performance,Geopy,我试图计算存储在一个数据框中的140万个点之间的距离,其中纬度和经度在单独的列中,热点(大约10个点)也在纬度和经度中,但这需要一些时间 我尝试下面的代码: from geopy import distance import pandas as pd def distance_rows(start, points): return min([distance(start, stop).km for stop in points]) df['distance'] = d

我试图计算存储在一个数据框中的140万个点之间的距离,其中纬度和经度在单独的列中,热点(大约10个点)也在纬度和经度中,但这需要一些时间

我尝试下面的代码:

from geopy import distance
import pandas as pd    

def distance_rows(start, points):
        return min([distance(start, stop).km for stop in points])

df['distance'] = df.apply(lambda row: distance_rows((row.LATITUDE, row.LONGITUDE), points), axis=1)

df是我的数据帧,distance_行接收点和大约10个点的列表,并返回从起点到点中每个点的最小距离

需要一段时间才能完成。您知道使用python计算数百万个点和一些感兴趣点之间距离的快速方法吗


我为我的英语道歉

目标是计算机1400万距离吗?还是要找出10个点中哪一个最接近1.4 M点?后者可以更快完成。目标是找出10个点中哪一个最接近1.4M点,然后结果必须是一个1.4M大小的数组,包含每个点的最小距离。这是一次性任务吗?如果需要几个小时才能完成,可以吗?然后写一些暴力代码。如果你需要一个距离函数,有很多问题可以提供“哈弗森”函数。谢谢!抱歉耽搁了!我希望它接近实时。。。每15分钟:DI有接近实时的例程——无需预计算(如您的问题所假定的那样)有些技术通常是几毫秒,很少超过20毫秒。够好吗?