始める無料で始める

補完結果をプロットする

複数の補完結果を見比べてプロットすることは、最適な補完手法を見極めるうえで不可欠です。この演習では、複数の補完手法に対してプロットを生成するための for ループを作成します。前のレッスンで実施した線形、2 次(quadratic)、最近傍(nearest)の各補間手法についてプロットを作成します。

それぞれの補完手法名を付けた 3 つの DataFrame(linear_interpquadratic_interpnearest_interp)は、すでにインポート済みです。

この演習はコースの一部です

Pythonで欠損データに対処する

コースを見る

演習の手順

  • 各補完手法ごとに 3 つのサブプロットを作成します。
  • linear_interpquadratic_interpnearest_interp の各 DataFrame を対応する補間手法にマッピングして、interpolations 辞書を作成します。
  • axesinterpolations をループ処理します。
  • interpolations から各 DataFrame を選び、df_key を使ってその DataFrame のタイトルを設定します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Set nrows to 3 and ncols to 1
fig, axes = plt.subplots(___, ___, figsize=(30, 20))

# Create a dictionary of interpolated DataFrames for looping 
interpolations = {'Linear Interpolation': ___, 'Quadratic Interpolation': ___, 
                  'Nearest Interpolation': ___}

# Loop over axes and interpolations
for ax, df_key in zip(___, ___):
  # Select and also set the title for a DataFrame
  interpolations[___].Ozone.plot(color='red', marker='o', linestyle='dotted', ax=ax)
  airquality.Ozone.plot(title=___ + ' - Ozone', marker='o', ax=ax)
  
plt.show()
コードを編集して実行