Session Ready
Exercise

State-to-State Flows

In the video, you saw a heatmap of state-to-state migration flows, but it was cluttered. In this exercise, you will look only at flows within the Midwest.

A data frame state_to_state has been loaded, and the first few rows are displayed in the console. Remember from the video that the row labels indicate the state moved to, while the column names indicate the state moved from.

A list midwest_states has been defined with the names of the Midwestern states. (Print it to the console if you would like to see what states it includes.) The data frame also uses state names for the column names and index, so you will use midwest_states to extract the columns and rows you want to use for this heatmap.

pandas and seaborn are imported using the usual aliases.

Instructions
100 XP
  • Subset the date frame to return only those columns matching the list of state names, and only those rows whose indexes are in the list of state names.
  • Subsetting may have reordered the columns and rows. Check whether midwest.index is equal to midwest.columns.
  • Sort the data frame by row index (axis = 0) and column name (axis = 1). Use inplace = True in both cases.
  • Create a heatmap of midwest. Apply a yellow-green-blue color ramp with cmap="YlGnBu".