使用「日期」資訊
我們很容易把時間戳當成純數字,但別忘了它通常對應到真實世界中發生的事件。這表示資料中常常隱含了額外資訊,例如「是否為平日?」或「是第幾季?」。這些資訊對於預測時間序列資料通常很有幫助。
在這個練習中,你會擷取這些以「日期/時間」為基礎的特徵。已經將一個單一的時間序列載入變數 prices。
本練習屬於課程
Python 的時間序列資料機器學習
練習說明
- 計算一年中的「星期幾」、月份,以及季度。
- 分別把它們加入到
prices_percDataFrame 的欄位中,欄位名稱依序為day_of_week、month_of_year、quarter_of_year。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Extract date features from the data, add them as columns
prices_perc['day_of_week'] = prices_perc.____.____
prices_perc['month_of_year'] = prices_perc.____.____
prices_perc['quarter_of_year'] = prices_perc.____.____
# Print prices_perc
print(prices_perc)