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.
Este exercício faz parte do curso
Analyzing US Census Data in Python
Instruções do exercício
mergesf_rentwith thesf_tractsgeopandas DataFrame, matching on thestate,countyandtractcolumns.- To map
median_rentin San Francisco, use thenotnull()method on themedian_rentcolumn to exclude a tract with missing data. - Map the
median_rent_pct_of_incomecolumn. Use the arrows in the plotting window to compare this map with the map ofmedian_rent. - Print the Pearson correlation between
median_rentandmedian_rent_pct_of_income.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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(____))