Skip to content

Latest commit

 

History

History
80 lines (51 loc) · 1.89 KB

census.rst

File metadata and controls

80 lines (51 loc) · 1.89 KB

Census

Overview

Connects to the Census API. It has been tested with the ACS and Economic Survey endpoints.

Note

Authentication
The API requires a key that you can get here (click on the box that says "Request a KEY")

Quickstart

To instantiate the Census class, either store your CENSUS_API_KEY as an environment variable or pass it as an argument:

from parsons import Census

# First approach: Use API key environment variables

# In Mac OS, for example, set your environment variables like so:
# export CENSUS_API_KEY='MY_CENSUS_KEY'

census = ActBlue()

# Second approach: Pass API key as arguments
actblue = ActBlue(api_key = 'MY_CENSUS_KEY')

Example 1

from parsons import Census
# year, dataset_acronym, variables and location tell the API what data we want
# for example, 'B01001_001E' is population and 'us:1' is the entire U.S.
year = '2019'
dataset_acronym = '/acs/acs1'
variables = 'NAME,B01001_001E'
location = 'us:1'

# here's our connector
census = Census(api_key=acs_key)

# now pull data into a Parsons table
t = census.get_census(year, dataset_acronym, variables, location)
print(t)

This example pulls the population of the US in 2019 from the ACS 1-year estimates.

Example 2

year = '2017'
dataset_acronym = '/ecnbasic'
variables = 'NAICS2017_LABEL,NAICS2017,GEO_ID,FIRM,PAYANN'
location = 'state:51'
census = Census(api_key=acs_key)

t = census.get_census(year, dataset_acronym, variables, location)
print(t)

This example pulls data on payroll by industry in Virginia from the 2017 Economic Census.

*API*

.. autoclass :: parsons.Census
   :inherited-members: