MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Analyzing US Census Data in Python

Lihat Kursus

Petunjuk latihan

  • Construct a range object with integers from 2011 to 2017
  • Create a column named "year", with its value set to the current value of the year variable
  • Set the median_home_value column data type to int
  • Create a lineplot of home values. Set the first parameter (x) to "year", set second parameter (y) to "median_home_value"

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode