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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file us_census_api_extract-0.0.1.tar.gz
.
File metadata
- Download URL: us_census_api_extract-0.0.1.tar.gz
- Upload date:
- Size: 5.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 462bcd4ea9d33b4f9840c878f8967b3b1d9c7c31a957472ca6ff0a949069cca5 |
|
MD5 | 99db34e7cadd416a855ef4915cb057e3 |
|
BLAKE2b-256 | 0feeccf7f5b47a41ac28fea2aabb1fe043fd3250f53095c2eed4bbdf89e608d2 |
File details
Details for the file us_census_api_extract-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: us_census_api_extract-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1cf32f4df4be294db63561eb6e669bd657225462393d291f73c8705587044e2 |
|
MD5 | f070469e531bdd3ef701c0726b8c6876 |
|
BLAKE2b-256 | dc78642c897998ff17748bc393950a8767886ad09663a7f7617194485b4f9b17 |