Unemployment
Unemployment varies by race and sex. In this exercise, you will start with a DataFrame, unemp_by_race, of percent unemployment by year for 25 to 54 year olds in four racial groups (White, Black, Asian, and Hispanic) and both sexes. You will create a bar plot of percent unemployment against year.
Because the column names will, after melting, become labels in your final plot, begin by providing column names that are shorter and clearer. The necessary code is provided at the beginning of the exercise.
pandas and seaborn have been imported with the usual aliases. unemp_by_race is loaded, and the dict you will use for renaming is displayed in the console.
Este ejercicio forma parte del curso
Analyzing US Census Data in Python
Instrucciones del ejercicio
melttheunemp_by_raceDataFrame; setid_varsto"year", and remove thevalue_varsparameter to use all remaining columns as value columns- Create a bar plot of
unemp_by_race, with the year on the x-axis and the percent unemployed on the y-axis, withhuedetermined the demographic group
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Rename columns
unemp_by_race.rename(columns = col_rename, inplace = True)
# Melt DataFrame by demographic group
unemp_by_race = unemp_by_race.melt(id_vars = ____, value_vars = ____,
var_name = "demographic", value_name = "pct_unemployed")
# Plot unemployment by group by year
sns.barplot(x = ____, y = ____, hue = ____, data = unemp_by_race)
plt.show()