Get startedGet started for free

Metropolitan Segregation

1. Metropolitan Segregation

You've been introduced to the Index of Dissimilarity, a common measure of segregation. We used states in our first lesson because it required less data prep, but social scientists usually analyze segregation by metropolitan area.

2. Metropolitan Statistical Area Map

Metropolitan, and the smaller Micropolitan Statistical Areas are groups of counties with a high degree of commuting among them. People often choose to live in a particular metropolitan area because of employment, but then have a wide selection of cities or neighborhoods within the metro area that will provide commuting access to their job. This is why MSAs are a natural unit of analysis for residential segregation.

3. Census API Request: Metro/Micropolitan Data

MSA data can be requested via the Census API, the same as other geographies in previous lessons. This setup: creating the base_url, creating a list of the variables to request...,

4. Census API Request: Metro/Micropolitan Data

...and building the predicates dictionary, should be familiar to you. One difference between the Decennial Census and ACS is that MSA data from the Decennial Census is only available in the state->MSA hierarchy. Since many MSAs cross state lines, this makes it hard to request data for the entire MSA. MSA data is available as a top-level geography for the ACS. Set the "for" predicate to "metropolitan statistical area/micropolitan statistical area".

5. Census API Request: Metro/Micropolitan Data

The request is executed... ...and the first few rows are displayed.

6. Census API Request: Metro/Micropolitan Data

This JSON response can be loaded into a pandas DataFrame. You can review the structure of this code in Chapter 1.

7. Metropolitan Area Definition

This is the tracts DataFrame we worked with previously. Notice it does not contain MSA identifiers, which we will need in order to analyze segregation by MSA. It does contain state and county identifiers, and MSAs are defined as collections of counties. What we need is the list of counties in each MSA. The counties that define an MSA are shown here in the DataFrame msa_def. This DataFrame is created from a delineation file downloaded from the Census. Notice that both DataFrames have a "state" and "county" column. We want to join these DataFrames, so that the MSA identifiers are associated with each tract. We can do this in pandas using the merge method. Let's see how this works.

8. Pandas Merge Method

Begin by importing pandas using the usual alias. Pick a variable name to hold the joined DataFrame. merge is called as a method of pandas.

9. Pandas Merge Method

The first two parameters are the two DataFrames to be joined. They are referred to as left and right. The left DataFrame is, literally, the DataFrame on the left of the line of code.

10. Pandas Merge Method

The join columns are specified in the left_on and right_on parameters. In this example *both* state and county must match for the rows to be joined. If the join columns have different names in the two DataFrames, the left_on/right_on syntax must be used. But if the join columns have the same names, as in this case, you can use the "on" parameter to avoid repeating the column names.

11. Pandas Merge Method

Sometimes the join key is in the DataFrame index. Let's say we want to add state names from DataFrame st to the tracts DataFrame. The identifier is in the index.

12. Pandas Merge Method

Call pd.merge. The left join key is still specified using left_on and the column name, "state". The right join key is specified with right_index = True. This is the resulting DataFrame.

13. Let's Practice

Let's use these tools to investigate metropolitan segregation.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.