Session Ready
Exercise

The API Response and Pandas

In this exercise you will load data from an API response object into a pandas data frame. You will assign user-friendly column names and convert the values from strings to appropriate data types.

After creating the data frame, run the sample code to create a scatterplot to visualize the relationship between average family size and median age in the United States.

requests and pandas (as pd) have already been imported. A response object r is loaded.

Instructions
100 XP
  • Build a list col_names of 4 new column names: name, median_age, avg_family_size, and state
  • Use the data frame constructor to create the data frame states. The data parameter should be set to r.json(), but use slicing to skip the first item, which contains the old column names
  • Use the astype method on each column to assign the correct data type.