MulaiMulai sekarang secara gratis

Specific Places

In this exercise you will practice looking up geographic identifiers for major cities. The Census classifies cities and other municipalities as "places". You will find place codes using the Geographic Codes Lookup at the Missouri Census Data Center

The variables to request are place names and total population.

The requests library has been imported and the base_url for the request is already set to request SF1 data for 2010.

Latihan ini adalah bagian dari kursus

Analyzing US Census Data in Python

Lihat Kursus

Petunjuk latihan

  • Using the Missouri Census Data Center, find (1) the two digit state code for Pennsylvania and (2) the five digit place codes for the cities of Philadelphia and Pittsburgh
  • Set the "for" predicate to request the two place codes you found for Philadelphia and Pittsburgh, separated by a comma
  • Set the "in" predicate to request the state code you found for Pennsylvania

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Build dictionary of predicates
get_vars = ["NAME", "P001001"] # <- total population
predicates = {}
predicates["get"] = ",".join(get_vars)
predicates["for"] = "place:____"
predicates["in"] = "state:____"

# Execute the request
r = requests.get(base_url, params=predicates)

# Show the response text
print(r.text)
Edit dan Jalankan Kode