Skip to main content

Extract US census data (as a DataFrame) by inputting a list of demographic variables and US state codes.

Project description

us_census_api_extract

This package makes it easy to extract US census data by inputting a list of demographic variables and US state codes. The results are returned as pandas DataFrame. As it extracts the data it keeps track of the progress and stores the batches in a temp folder. If the process gets interrupted, you can run it again and it will continue where it left off (ie. it is idempotent).

Install

pip install us_census_api_extract

Usage

Go to the US census page to get an api key. In the example below I am using the American 5-year Community Survey (2018) but you could use any api by changing the 'request_url_pre'.

request_url_pre = "https://api.census.gov/data/2018/acs/acs5/subject?get=NAME,"
request_url_post_1 = "&for=tract:*&in=state:"
request_url_post_2 = "&in=county:*&key="
api_key = your-api-key

state_codes = ['48',  # TX
               '36',  # NY
               '06']  # CA

vars = ['S0101_C01_001E', 'S0101_C01_002E', 'S0101_C01_003E',
       'S0101_C01_004E', 'S0101_C01_005E', 'S0101_C01_006E',
       'S0101_C01_007E', 'S0101_C01_008E', 'S0101_C01_009E',
       'S0101_C01_010E', 'S0101_C01_011E', 'S0101_C01_012E']

tmp_path = your-temp-filepath  # this is where the temp files extracted will be stored.

# extract census demographics from US Census API for all census tracts that are in Texas
df_demo = cenx.extract_by_var(vars, state_codes,
                              request_url_pre, request_url_post_1, request_url_post_2, api_key, 
                              tmp_path)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

us_census_api_extract-0.2.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

us_census_api_extract-0.2.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file us_census_api_extract-0.2.3.tar.gz.

File metadata

  • Download URL: us_census_api_extract-0.2.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3

File hashes

Hashes for us_census_api_extract-0.2.3.tar.gz
Algorithm Hash digest
SHA256 087fc14759b41ed43e6bd985e8cdc02ecd57fc9dd90d71b65c6fee1b65e6b252
MD5 195b9a00d781ffe62827f8e7aa2daab4
BLAKE2b-256 208b0a4749242b8e02458a3350973de2fb95dc87a7ec8d0cf75b01cf369d9cb2

See more details on using hashes here.

File details

Details for the file us_census_api_extract-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: us_census_api_extract-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3

File hashes

Hashes for us_census_api_extract-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5a55a32011b75917d513e0d674a5488251e9f27d04e884e4ab3c4be5bb8b5156
MD5 2b13b23c998221f346c0b07e8729ce3c
BLAKE2b-256 9c57f1e65e8e623f3a5f916fd7bdb212e56e6834b2f1d0ce5aa9f4e2ad93074d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page