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.
Deze oefening maakt deel uit van de cursus
Improving Your Data Visualizations in Python
Oefeninstructies
- Filter the data in the first
sns.kdeplot()call to include only the year2012. - Shade under the first KDE with the
shadeargument. - Add the label
'2012'for the plot legend. - Repeat the first three steps for second
sns.kdeplot()call, but filter the data to not include2012. Use the label'other years'.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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()