Get startedGet started for free

Labor Force Participation

Unemployment could be going down because labor force participation is decreasing, that is, fewer people are looking for work! In this exercise, you will investigate that possiblity. You will start with a DataFrame, lf_by_race, of percent labor force participation 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 labor force participation against year. In order to condition the bar plot by demographic group, you will first melt the DataFrame. The DataFrame already has suitable column names.

pandas and seaborn have been imported with the usual aliases. unemp_by_race is loaded and five columns are displayed in the console.

This exercise is part of the course

Analyzing US Census Data in Python

View Course

Exercise instructions

  • melt the lf_by_race DataFrame, setting var_name to "demographic" and value_name to "labor_force_participation"; can you determine the appropriate column for the id_vars parameter?
  • Call sns.barplot with the year on the x-axis and labor force participation on the y-axis; then use the hue parameter to show sex grouped by year.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Melt DataFrame by demographic group
lf_by_race = lf_by_race.melt(
        ____,
        ____,
        ____
		)

# Plot labor force particpation by group by year
sns.barplot(____)
plt.show()
Edit and Run Code