將 UDF 套用到向量資料
已提供名為 df 的 dataframe,其中包含一個型別為 vector 的欄位 output。主控台已顯示其前 5 列。
也已提供 UDF get_first_udf,可選取向量欄位的第一個元素。
本練習屬於課程
Python Spark SQL 入門
練習說明
- 在
df中新增一個欄位來建立新的 dataframedf_new。將新欄位命名為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.____