ComeçarComece de graça

Comparing with two KDEs

Imagine that you work for the premier air-filter provider. Your company has asked you to build a report that looks into why 2012 was a particularly good year for sales of your ozone (O3) filter. You downloaded some helpful pollution data from the USGS, and you want to make a concise visualization that compares the general pattern of O3 pollution for 2012 to all other years on record.

To do this, you can build two overlaid kernel density estimation plots (KDEs): one for 2012 O3 data and one for all other years.

Este exercício faz parte do curso

Improving Your Data Visualizations in Python

Ver curso

Instruções do exercício

  • Filter the data in the first sns.kdeplot() call to include only the year 2012.
  • Shade under the first KDE with the shade argument.
  • Add the label '2012' for the plot legend.
  • Repeat the first three steps for second sns.kdeplot() call, but filter the data to not include 2012. Use the label 'other years'.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Filter dataset to the year 2012
sns.kdeplot(pollution[pollution.year ____ ____].O3, 
            # Shade under kde and add a helpful label
            shade = ____,
            ____ = '____')

# Filter dataset to everything except the year 2012
sns.kdeplot(pollution[pollution.year ____ ____].O3, 
            # Again, shade under kde and add a helpful label
            shade = ____,
            ____ = '____')
plt.show()
Editar e executar o código