Tract Demographics in a Segregated City
The first few rows of the tracts_cook
DataFrame appear in the console. In this exercise, you will calculate the percent African-American in two time periods, examine the histogram of this variable for 2010, and then plot them against each other to see how they have changed. You will observe that tracts with a mix of Black and other races are more likely to increase their percentage of black residents over time.
pandas
and seaborn
are loaded using the usual aliases.
This exercise is part of the course
Analyzing US Census Data in Python
Exercise instructions
- Calculate the percent African-American of each tract in 2010 as
100
times the Black population in that year divided by the total population in that year - Call
sns.distplot
on the newpct_black_2010
column of thetracts_cook
DataFrame; make sure to setkde
toFalse
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate percent Black in 2010
tracts_cook["pct_black_2010"] = 100 * ____ / ____
# Examine histogram of percent Black
sns.distplot(____, ____)
plt.show()