データの集計値をプロットする

Pythonで学ぶ時系列データの可視化

Thomas Vincent

Head of Data Science, Getty Images

移動平均

  • 時系列分析における移動平均の主な用途:
    • 短期的な変動の平滑化
    • 外れ値の除去
    • 長期的なトレンドやサイクルの抽出
Pythonで学ぶ時系列データの可視化

移動平均モデル

co2_levels_mean = co2_levels.rolling(window=52).mean()

ax = co2_levels_mean.plot()
ax.set_xlabel("Date")
ax.set_ylabel("The values of my Y axis")
ax.set_title("52 weeks rolling mean of my time series")

plt.show()
Pythonで学ぶ時系列データの可視化

CO2データの移動平均プロット

時系列のローリング平均

Pythonで学ぶ時系列データの可視化

時系列の集計値を計算する

co2_levels.index
DatetimeIndex(['1958-03-29', '1958-04-05',...],
              dtype='datetime64[ns]', name='datestamp', 
              length=2284, freq=None)
print(co2_levels.index.month)
array([ 3,  4,  4, ..., 12, 12, 12], dtype=int32)
print(co2_levels.index.year)
array([1958, 1958, 1958, ..., 2001,
      2001, 2001], dtype=int32)
Pythonで学ぶ時系列データの可視化

時系列の集計値をプロットする

index_month = co2_levels.index.month
co2_levels_by_month = co2_levels.groupby(index_month).mean()
co2_levels_by_month.plot()

plt.show()
Pythonで学ぶ時系列データの可視化

時系列の集計値をプロットする

CO2レベルデータの月次集計

Pythonで学ぶ時系列データの可視化

練習しましょう!

Pythonで学ぶ時系列データの可視化

Preparing Video For Download...