将 UDF 应用于向量数据
已经提供名为 df 的 dataframe,其中包含一个类型为 vector 的列 output。其前 5 行已在控制台中显示。
提供了一个 UDF get_first_udf,用于选取向量列的第一个元素。
本练习是课程的一部分
Python 中的 Spark SQL 入门
练习说明
- 通过给
df添加新列创建一个名为df_new的新 dataframe。将新列命名为label。 - 显示
df_new的前 5 行。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Add label by applying the get_first_udf to output column
df_new = df.____('____', ____('____'))
# Show the first five rows
df_new.____