檢查欄位型別
使用 .info() 方法查看 UFO 資料集的欄位型別。有兩個欄位需要轉換:seconds 欄位是數值欄位,但目前被讀成 object;以及 date 欄位,可以轉換成 datetime 型別。這樣之後做特徵工程會更容易。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 對
ufo資料集呼叫.info()方法。 - 將
seconds欄位的型別轉為float。 - 將
date欄位的型別轉為datetime。 - 再次對
ufo呼叫.info(),檢查變更是否生效。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the DataFrame info
print(ufo.____)
# Change the type of seconds to float
ufo["seconds"] = ____
# Change the date column to type datetime
ufo["date"] = ____
# Check the column types
print(ufo.____)