Global median per capita income over time
The seaborn barplot() function shows point estimates and confidence intervals as rectangular bars; the default function displays the mean, but it can also represent another summary statistic if you pass a particular numpy function to its estimator parameter:
seaborn.barplot(x=None, y=None, data=None, estimator=<function mean>, ...)
In this exercise, you will use an imported World Bank dataset containing global income per capita data for 189 countries since the year 2000. To practice displaying summary statistics per category, you will plot and compare the median global income per capita since 2000 to the mean.
pandas as pd, numpy as np, matplotlib.pyplot as plt, and seaborn as sns have been imported. The global income data is available in your workspace in income_trend.
Este exercício faz parte do curso
Importing and Managing Financial Data in Python
Instruções do exercício
- Inspect
income_trendusing.info(). - Create a
sns.barplot()using the column'Year'forxand'Income per Capita'fory, and show the result after rotating thexticksby 45 degrees. - Use
plt.close()after the initialplt.show()to be able to show a second plot. - Create a second
sns.barplot()with the samexandysettings, usingestimator=np.medianto calculate the median, and show the result.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Inspect the data
income_trend.____()
# Create barplot
sns.barplot(x=____, y='Income per Capita', data=____)
# Rotate xticks
plt.____(____=____)
# Show the plot
plt.show()
# Close the plot
plt.close()
# Create second barplot
sns.barplot(x=____, y='Income per Capita', data=____, estimator=____)
# Rotate xticks
plt.____(____)
# Show the plot
plt.show()