Commuting
1. Commuting Patterns
Welcome back! In this lesson, we will look at ACS commuting data.2. Commuting Tables
The ACS contains data on subjects such as... the means (or mode) of transportation... time spent commuting... time leaving for and arriving at work, as well as crosstabs by demographic characteristics, such as means of transportation by race, or travel time by sex. Additionally, these data are available based on the geographies where people sleep... or where they work. Thus one could find the number of *workers arriving* in a Census tract at 7am, or arriving by bicycle.3. Congestion Pricing in New York City
In early 2019, New York City began the planning process for a congestion fee on automobile traffic into Manhattan. A similar proposal in 2007 died, ... partially due to criticism that it would hurt lower-income car commuters. How many such commuters would be affected?4. Means of Transportation
We can answer this question using Table B08519. This is a workplace geography table. It provides characteristics for people who work in Manhattan. This table contains counts of workers by 6 commute modes, crossed with 8 income categories. We won't need the subtotals, and will omit them from the API request.5. API Response
Assume we've just completed an API request. The response object contains a row of column names, and a row of data. We will discard the column names, and break the data into rows by commute mode. Note the GEOIDs in the final two columns. We won't need these and will remove them in the next step.6. Reshaping the Data
First read the data_row into a variable. The JSON response is a list of lists. Index 1 returns the second row, which contains the data. Index :-2 drops the state and county identifiers in the final two elements of that row. Next, use a list comprehension to reshape the data_row. Each commute mode has counts for 8 income classes, so define a variable iter_len = 8. We want to pull items 8 at a time and put them in new lists. We do this in a list comprehension. i varies from 0, to the length of the list, and increases by the iter_len, 8. When i is 0, elements 0 to 7 are extracted. When i is 8, elements from 8 to 15 are extracted, and so on to the end of the row. The result, data, is a list of lists.7. Constructing the DataFrame
We would like to create a heatmap of this data. The DataFrame row names and column names will appear in the heatmap, so let's define sensible names for them based on commute modes... and income classes. We've created a DataFrame this way before. The only new thing is that we use the index parameter to create the DataFrame with intelligible row names, taken from the modes list.8. Constructing the DataFrame
When we're done, the DataFrame looks like this.9. Constructing the Heatmap
Now that the DataFrame has been reshaped, we can pass it to sns.heatmap. The annot parameter adds an annotation. This can be a DataFrame of the same shape. We divide each value in the DataFrame by 1000, to show thousands of commuters in each bin. fmt="d" formats the annotations as an integer. What we see is that the vast majority of Manhattan workers commute by public transportation. There are relatively few car commuters in the low and middle income categories who might be impacted by a congestion fee.10. Let's practice!
Now it's your turn to create heatmaps and cartographic maps.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.