開始使用免費開始

將 UDF 套用到向量資料

已提供名為 df 的 dataframe,其中包含一個型別為 vector 的欄位 output。主控台已顯示其前 5 列。

也已提供 UDF get_first_udf,可選取向量欄位的第一個元素。

本練習屬於課程

Python Spark SQL 入門

檢視課程

練習說明

  • df 中新增一個欄位來建立新的 dataframe df_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.____
編輯並執行程式碼