Home Values in California
California's major cities have been in the news for skyrocketing housing prices. How has the median home value changed over the last several years? In this exercise you will use a loop to request variable B25077_001E from seven ACS years and plot the value over time.
The predicates dictionary has been created, and is printed to the console. Notice that state:06 sets the GEOID for California. pandas and seaborn have been imported using the usual aliases. HOST and dataset have been defined, and dfs is an empty list that has been initialized as a collector for the requested DataFrames.
This exercise is part of the course
Analyzing US Census Data in Python
Exercise instructions
- Construct a
rangeobject with integers from 2011 to 2017 - Create a column named
"year", with its value set to the current value of theyearvariable - Set the
median_home_valuecolumn data type toint - Create a lineplot of home values. Set the first parameter (
x) to"year", set second parameter (y) to"median_home_value"
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Loop over years 2011 to 2017
for year in ____:
base_url = "/".join([HOST, str(year), dataset])
r = requests.get(base_url, params=predicates)
df = pd.DataFrame(columns=col_names, data=r.json()[1:])
# Add column to df to hold year value, append df to collector dfs
____
dfs.append(df)
# Concatenate all DataFrames, fix column type
states = pd.concat(dfs, ignore_index=True)
states["median_home_value"] = ____
sns.lineplot(____, ____, data = states)
plt.show()