視覺化多個時間序列的季節性
你現在要從 jobs_decomp 中擷取 seasonality 成分,來視覺化這些時間序列的季節性。請注意,在繪圖前需要先用 pd.DataFrame.from_dict() 函式,將 seasonality 成分的字典轉換為 DataFrame。
空字典 jobs_seasonal 和上一個練習中的時間序列分解物件 jobs_decomp 已提供在你的工作區。
本練習屬於課程
使用 Python 視覺化時間序列資料
練習說明
- 逐一走訪
jobs_names中的每個欄位名稱,從jobs_decomp取出對應的seasonal成分。將結果放入jobs_seasonal:鍵為時間序列名稱(欄位名),值為該時間序列的seasonal成分。 - 將
jobs_seasonal轉為 DataFrame,命名為seasonality_df。 - 為
seasonality_df的 16 個欄位建立分面圖。請確保各子圖不要共用 y 軸。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Extract the seasonal values for the decomposition of each time series
for ts in ____:
jobs_seasonal[ts] = jobs_decomp[ts]____
# Create a DataFrame from the jobs_seasonal dictionary
____ = ____(jobs_seasonal)
# Remove the label for the index
seasonality_df.index.name = None
# Create a faceted plot of the seasonality_df DataFrame
____(subplots=____,
layout=____,
sharey=____,
fontsize=2,
linewidth=0.3,
legend=False)
# Show plot
plt.show()