我的 Dataframe :
DF = spark.createDataFrame([[114.038696, 22.5315, 114.047302, 22.531799], [ 114.027901, 22.5228, 114.026299, 22.5238], [ 114.026299, 22.5238,114.024597,22.5271], [114.024597, 22.5271,114.024696,22.527201]], list('ABCD'))
DF.show()
+----------+-------+----------+---------+
| A| B| C| D|
+----------+-------+----------+---------+
|114.038696|22.5315|114.047302|22.531799|
|114.027901|22.5228|114.026299| 22.5238|
|114.026299|22.5238|114.024597| 22.5271|
|114.024597|22.5271|114.024696|22.527201|
+----------+-------+----------+---------+
(A, B)
&(C, D)
为两点坐标;column A
和column C
为纬度;column B
和column D
为经度;
我想计算这两点之间的地理距离。
我试着:
from geopy.distance import geodesic
DF = DF.withColumn('Lengths/m', geodesic((['B'],['A']), (['D'],['C'])).m)
然后我得到错误:
TypeError:float()参数必须是字符串或数字,而不是"list"
要成功计算地理距离,我应该采取哪些不同的做法?
1条答案
按热度按时间fkaflof61#
您需要定义一个自定义user-defined-function: