從日期建立特徵
另一個要執行的特徵工程任務是擷取月份與年份。請在 ufo 資料集的 date 欄位上完成這個任務。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 列印出
date欄位的.head()。 - 取出
date欄位的月份屬性。 - 取出
date欄位的年份屬性。 - 檢視
date、month與year這些欄位的.head()。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Look at the first 5 rows of the date column
print(____)
# Extract the month from the date column
ufo["month"] = ufo["date"].____
# Extract the year from the date column
ufo["year"] = ufo["date"].____
# Take a look at the head of all three columns
print(____)