IniziaInizia gratis

Plot interpolations

Plotting comparative graphs for the imputations is essential for inferring the best imputation technique. In this exercise, you'll create a for loop for generating plots for multiple imputation techniques. You will create the plots of the imputations you performed in the previous lesson i.e., the linear, the quadratic, and the nearest interpolation techniques.

Three DataFrames named after their imputation techniques have already been imported for you, namely, linear_interp, quadratic_interp, and nearest_interp

Questo esercizio fa parte del corso

Dealing with Missing Data in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Create 3 subplots for each imputation technique.
  • Create the interpolations dictionary by mapping the linear_interp, quadratic_interp, and nearest_interp DataFrames to the relevant interpolation technique.
  • Loop over axes and interpolations.
  • Select each DataFrame in interpolations and set the title for a DataFrame using df_key.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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()
Modifica ed esegui il codice