將班機與其目的地機場進行連接
你受聘為一家全球旅遊公司的資料工程師。你的第一個任務是透過分析航班資料,協助公司提升營運。你的工作區中已有兩個資料集:一個包含航班詳細資訊(flights),另一個包含目的地機場資訊(airports),兩者都已可在你的工作區使用。
你的目標是?將這兩個資料集合併,建立一個能把每個航班連結到其目的地機場的強大資料集。
本練習屬於課程
PySpark 入門
練習說明
- 檢視
airportsDataFrame,留意可用來將airports與flights表連接的鍵欄位。 - 在
"dest"欄位上將flights與airportsDataFrame 進行連接。將結果儲存為flights_with_airports。 - 再次檢視
flights_with_airports,留意新增了哪些資訊。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Examine the data
airports.____()
# .withColumnRenamed() renames the "faa" column to "dest"
airports = airports.withColumnRenamed("faa", "dest")
# Join the DataFrames
flights_with_airports = ____
# Examine the new DataFrame
flights_with_airports.____