Distribution of inflation rates in China, India, and the US
As you saw in the video, the boxplot() function displays key quantiles of a distribution with respect to categories, where y represents a quantitative variable, and x a categorical variable. In statistics, this kind of distribution is known as a box-and-whisker plot.
A complement to a box plot is a swarmplot(), which draws a categorical scatterplot that displays all categorical observations without overlapping; it takes similar arguments to boxplot():
seaborn.boxplot(x=None, y=None, data=None, ...)
seaborn.swarmplot(x=None, y=None, data=None, ...)
In this final exercise, you will compare the historical distributions of inflation rates by country - specifically China, India, and the US - instead of by time series trends. pandas as pd, matplotlib.pyplot as plt, and seaborn as sns have been imported for you. The FRED inflation data is in your workspace as inflation.
Este exercício faz parte do curso
Importing and Managing Financial Data in Python
Instruções do exercício
- Create and show a boxplot of the
inflationdata with'Country'forxand'Inflation'fory. - Create and show
sns.swarmplot()with the same arguments.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Create boxplot
sns.____(x=____, y=____, data=____)
# Show the plot
plt.show()
# Close the plot
plt.close()
# Create swarmplot
sns.swarmplot(x=____, y=____, data=____)
# Show the plot
plt.show()