在Pyspark上,我定义了一个UDF如下:
from pyspark.sql.functions import udf
from scipy.spatial.distance import cdist
def closest_point(point, points):
""" Find closest point from a list of points. """
return points[cdist([point], points).argmin()]
udf_closest_point = udf(closest_point)
dfC1 = dfC1.withColumn("closest", udf_closest_point(dfC1.point, dfC1.points))我的数据是这样的:
对于我的UDF,我应该更改什么来返回一个浮点数数组,而不是一个字符串?
发布于 2017-11-22 18:37:30
可以将UDF的返回类型指定为浮点数ArrayType(FloatType())数组。
from pyspark.sql.types import ArrayType, FloatType
udf_closest_point = udf(closest_point, ArrayType(FloatType()))https://stackoverflow.com/questions/47441689
复制相似问题