BaşlayınÜcretsiz Başlayın

The Basic API Request

In this exercise, you will construct an API request to retrieve the average family size and median age for all states in the United States. The data will come from Summary File 1 of the 2010 Decennial Census.

requests has been imported for you.

Bu egzersiz

Analyzing US Census Data in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Specify appropriate string values for year and dataset to retrieve data for 2010 from Summary File 1 of the Decennial Census
  • Construct get_vars, the list of Census variables to request, with the following variable names: "NAME", "P013001" (median age), "P037001" (average family size)
  • Output r.text using the print function

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Build base URL
HOST = "https://api.census.gov/data"
year = ____
dataset = ____
base_url = "/".join([HOST, year, dataset])

# Specify Census variables and other predicates
get_vars = ____
predicates = {}
predicates["get"] = ",".join(get_vars)
predicates["for"] = "state:*"

# Execute the request, examine text of response object
r = requests.get(base_url, params=predicates)
print(____)
Kodu Düzenle ve Çalıştır