I was following this tutorial for requesting from the 2010 Decennial Census. It specifies the following code for printing a list of state names ("NAME"), state areas ("AREALAND"), and state total populations ("P001001"):

import requests

HOST = "https://api.census.gov/data"
year = "2010"
dataset = "dec/sf1"

base_url = "/".join([HOST, year, dataset])

predicates = {}

get_vars = ["NAME", "AREALAND", "P001001"]

predicates["get"] = ",".join(get_vars)

predicates["for"] = "state:*"

col_names = ["name", "total_pop", "state"]
r = requests.get(base_url, params = predicates)

print (r.text)

When I run the code I get the following error:

error: error: unknown variable 'AREALAND'

Looking at the 2010 Decennial Census Variable List I don't see 'AREALAND' listed. Has the API been changed since the tutorial was made, or am I making some other kind of error? The tutorial was published to YouTube on March 4th, 2020.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.