移除欄與列
你先前已從 CSV 檔載入航空班機資料。你將要建立一個模型,用來預測某班航班是否會延誤。
在這個練習中,你需要先精簡資料,方式包括:
- 移除一個沒有資訊量的欄位,及
- 移除沒有「是否延誤」資訊的列。
資料已存為 flights。
注意: 你可以回顧 IPython Shell 旁 Slides 面板中的課程投影片,應該會很有幫助。
本練習屬於課程
使用 PySpark 的機器學習
練習說明
- 移除
flight欄位。 - 找出
delay欄位中有遺漏值的紀錄數量。 - 移除
delay欄位中有遺漏值的紀錄。 - 移除任一欄位有遺漏值的紀錄,並取得剩餘列數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Remove the 'flight' column
flights_drop_column = flights.____(____)
# Number of records with missing 'delay' values
flights_drop_column.____('delay IS NULL').____()
# Remove records with missing 'delay' values
flights_valid_delay = flights_drop_column.____(____)
# Remove records with missing values in any column and get the number of remaining rows
flights_none_missing = flights_valid_delay.____()
print(flights_none_missing.____())