开始使用免费开始使用

绘制插值结果

对比绘制各类插补结果的图表,有助于判断哪种插补方法更合适。本练习中,您将编写一个 for 循环,为多种插补技术生成图表。您将为上一课中完成的三种插值插补方法绘图,即线性、二次以及最近邻插值。

以各自插补方法命名的 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()
编辑并运行代码