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

Exercise

Zip Code Tabulation Areas

In the marketing field, it is very common to want to know ZIP Code demographics. ZIP Code Tabulation Areas ("ZCTAs") are Census-defined equivalents to ZIP Codes that are built out of Census blocks. In this exercise you will request total population for all ZCTAs in the state of Alabama.

In pandas, an index can be used to retrieve particular rows. The GEOIDs are suitable row identifiers. In this exercise you will set a multilevel index based on the state and ZCTA of each row.

The requests and pandas packages have been imported. The base_url is defined, as is the predicates dictionary with the list of variables to request.

Instructions

100 XP
  • Set the "for" key in the predicates dict to return all ZCTAs; spell out the geography in full as "zip code tabulation area (or part)""
  • Set the "in" key in the predicates dict to only return ZCTAs in the state of Alabama; you will have to look up the FIPS code for Alabama in one of the online sources you have learned about
  • Set the DataFrame index to be the concatenation of the state and zcta columns. Use inplace = True to not create a new DataFrame.