補完結果をプロットする
複数の補完結果を見比べてプロットすることは、最適な補完手法を見極めるうえで不可欠です。この演習では、複数の補完手法に対してプロットを生成するための for ループを作成します。前のレッスンで実施した線形、2 次(quadratic)、最近傍(nearest)の各補間手法についてプロットを作成します。
それぞれの補完手法名を付けた 3 つの DataFrame(linear_interp、quadratic_interp、nearest_interp)は、すでにインポート済みです。
この演習はコースの一部です
Pythonで欠損データに対処する
演習の手順
- 各補完手法ごとに 3 つのサブプロットを作成します。
linear_interp、quadratic_interp、nearest_interpの各 DataFrame を対応する補間手法にマッピングして、interpolations辞書を作成します。axesとinterpolationsをループ処理します。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()