1. Learn
  2. /
  3. Courses
  4. /
  5. Analyzing US Census Data in Python

Exercise

White and Black Unemployment

In this exercise you will compare metropolitan unemployment between White and Black males. msa_black_emp is loaded. A new DataFrame, msa_white_emp, with data from table C23002A from the 2012 5-year ACS is also loaded. Percentage unemployment has already been calculated for you. You will restrict both DataFrames to the columns of interest (the ones showing percentage male employment), join the DataFrames, and melt them into a tidy DataFrame for visualization with seaborn.

pandas and seaborn have been loaded using the usual aliases.

Instructions

100 XP
  • Create tidy_white_emp by restricting msa_white_emp to the columns "msa" and "pct_male_unemp", then rename the second column to "white"
  • Merge tidy_black_emp and tidy_white_emp on the "msa" column; assign to tidy_emp
  • Use melt on tidy_emp. The value_vars should be the names of the two race columns; set var_name to "race" and value_name to "unemployment"
  • Plot unemployment vs. dissimilarity, conditioning on race using the hue parameter