Get startedGet started for free

High Rent and Rent Burden

Rents can be very high in places like San Francisco, but to understand the geography of rent burden, looking at gross rents may not be as useful as looking at the share of income spent on rent.

In this exercise, you will join a DataFrame with gross rents in dollars (median_rent) and as a percentage of income (median_rent_pct_of_income) by Census tract in San Francisco with a geopandas DataFrame of those tracts. You will then map and compare these two variables. Darker colors in the maps indicate higher values (higher rents, or higher rent share of income).

The first few rows of these two columns are displayed in the console.

pandas and geopandas are imported using the usual aliases.

This exercise is part of the course

Analyzing US Census Data in Python

View Course

Exercise instructions

  • merge sf_rent with the sf_tracts geopandas DataFrame, matching on the state, county and tract columns.
  • To map median_rent in San Francisco, use the notnull() method on the median_rent column to exclude a tract with missing data.
  • Map the median_rent_pct_of_income column. Use the arrows in the plotting window to compare this map with the map of median_rent.
  • Print the Pearson correlation between median_rent and median_rent_pct_of_income.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Merge geometries with rent data
sf_tracts = sf_tracts.merge(____, ____)

# Plot median rent by Census tract
sf_tracts[____].plot(column = "median_rent", cmap = "YlGnBu")
plt.show()
plt.close()

# Plot median rent as percentage of income
sf_tracts.plot(____, cmap = "YlGnBu")
plt.show()

# Show correlation between median rent and percent of income
print(sf_tracts["median_rent"].corr(____))
Edit and Run Code