2

So, this is my first time using the Census API (or any API at all), and I have had some amount of luck so far. Rather than using the census package or cenpy, I have just been creating the URL's by hand since it is not that difficult.

For example, the following successfully gets me the number of people who speak different languages by state and congressional district.

This Works:

import requests
import pandas as pd


r = requests.get('https://api.census.gov/data/2016/acs/acs1/subject?get=S1601_C01_002E,S1601_C01_004E,S1601_C01_008E,S1601_C01_012E&for=congressional%20district:*&in=state:*&key=<my key>')
r.status_code
data = r.json()
df = pd.DataFrame(data)
header = df.iloc[0]
df = df[1:]
df.columns = header
lang = df.rename(columns = {'congressional district': 'cd',
                 'S1601_C01_002E': 'English',
                 'S1601_C01_004E': 'Spanish',
                 'S1601_C01_008E': 'IndoEuropean',
                 'S1601_C01_012E': 'AsianPacific'})

However, I am now interested retrieving a variable that is a percentage. When I try to pull it, I get -888888888 for all the values in the field. I'm assuming there is a simple way to retrieve this data in the correct format that I am missing. Anyone know what that is?

Faulty Code:

r = requests.get('https://api.census.gov/data/2016/acs/acs1/subject?get=S1501_C01_015E&for=congressional%20district:*&in=state:*&key=<my key>')
r.status_code
data = r.json()

Results:

 [['S1501_C01_015E', 'state', 'congressional district'],
 ['-888888888', '01', '01'],
 ['-888888888', '01', '02'],
 ['-888888888', '01', '03'],
 ['-888888888', '01', '04'],
 ['-888888888', '01', '05'],...
Martin Gergov
  • 1,556
  • 4
  • 20
  • 29
Audrey
  • 43
  • 4
  • If you hit the URL directly (with a browser or curl) do you get the same results? – MrName Nov 27 '17 at 16:54
  • 2
    This seems like an error with the Census API itself, and not your code, no? I assume you can recreate the same API response directly in a web browser? – David Cain Nov 27 '17 at 16:59
  • 2
    @DavidCain, You are correct. Definitely a Census API situation. Apparently, that is their code for data they no longer maintain, despite maintaining the fields. – Audrey Nov 27 '17 at 17:35

0 Answers0