📅  最后修改于: 2022-03-11 15:01:04.642000             🧑  作者: Mango
import pyspark.sql.functions as F
import pyspark.sql.types as T
#or: to_array = F.udf(lambda v: list([float(x) for x in v]), T.ArrayType(T.FloatType()))
to_array = F.udf(lambda v: v.toArray().tolist(), T.ArrayType(T.FloatType()))
df = df.withColumn('features', to_array('features'))