PySpark - Pass list as parameter to UDF

前端 未结 3 516
挽巷
挽巷 2020-12-13 21:27

I need to pass a list into a UDF, the list will determine the score/category of the distance. For now, I am hard coding all distances to be the 4th score.

a=         


        
3条回答
  •  春和景丽
    2020-12-13 21:53

    Try currying the function, so that the only argument in the DataFrame call is the name of the column on which you want the function to act:

    udf_score=udf(lambda x: cate(label_list,x), StringType())
    a.withColumn("category", udf_score("distances")).show(10)
    

提交回复
热议问题