開始使用免費開始

使用惰性處理

惰性處理的操作通常會在差不多的時間內回傳結果,而不太受實際資料量影響。記得,這是因為 Spark 直到發出動作(action)時才會真正執行轉換(transformation)。

在這個練習中,我們會定義一個 DataFrame(aa_dfw_df),並加入幾個轉換。請注意:在只定義轉換時與實際查詢資料時,轉換完成所需的時間差異。這些差異可能不大,但會感覺得到。當你在完整的 Spark 叢集上處理更大量的資料時,差異會更加明顯。

本練習屬於課程

使用 PySpark 清理資料

檢視課程

練習說明

  • 載入 DataFrame。
  • Destination Airport 欄位加入 F.lower() 的轉換。
  • 顯示 DataFrame,並留意此動作完成所需的時間差異。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Load the CSV file
aa_dfw_df = ____.____.____('csv').options(Header=True).load('AA_DFW_2018.csv.gz')

# Add the airport column using the F.lower() method
aa_dfw_df = aa_dfw_df.withColumn('airport', ____(aa_dfw_df['Destination Airport']))

# Show the DataFrame
____
編輯並執行程式碼