Census data for arbitrary geographies
Project description
This library extends the Sunlight Foundation’s Census API Wrapper to allow querying Census tracts, block groups, and blocks by Census place, as well as by arbitrary geographies.
Usage
from census_area import Census c = Census("MY_API_KEY") old_homes = c.acs5.state_place_tract(('NAME', 'B25034_010E'), 17, 14000)
The call above will return the name of the census tract and the number of homes that were built before 1939 for every tract in the City of Chicago. 17 is the FIPS code for Illinois and 14000 is the FIPS code for Chicago.
By default, this method will return a list of dictionaries, where each dictionary represents the data for one tract.
With the keep_geometry argument, you can have the method return a geojson-like dictionary. Each tract is a feature, and the census variables about the tract appear in the feature’s property attributes.
old_homes_geojson = c.acs5.state_place_tract(('NAME', 'B25034_010E'), 17, 14000), keep_geometry=True)
There are similar methods for block groups
old_home_block_groups = c.acs5.state_place_blockgroup(('NAME', 'B25034_010E'), 17, 14000))
And blocks. Not that block level geographies are only available for the short-form data from the Decennial Census
owner_occupied = c.sf1.state_place_block(('NAME', 'H016F0002'), 17, 14000)
The tract and blockgroup methods are also available for the Decennial Census.
owner_occupied_blockgroup = c.sf1.state_place_tract(('NAME', 'H016F0002'), 17, 14000) owner_occupied_tract = c.sf1.state_place_blockgroup(('NAME', 'H016F0002'), 17, 14000) old_homes = c.sf3.state_place_tract('NAME', 'H034010'), 17, 14000) old_homes = c.sf3.state_place_blockgroup('NAME', 'H034010'), 17, 14000)
In addition to these convenient methods, there are three lower level ways to get census tracts, blocks, and groups for arbitrary geometries.
import json my_shape_geojson = json.load('my_shape.geojson') features = [] old_homes = c.acs5.geo_tract(('NAME', 'B25034_010E'), my_shape_geojson['geometry']) for tract_geojson, tract_data in old_homes: tract_geojson['properties'].update(tract_data) features.append(tract) my_shape_with_new_data_geojson = {'type': "FeatureCollection", 'features': features}
The method takes in the census variables you want and a geojson geometry, and returns a generator of the tract shapes, as geojson features, and the variables for that tract. You have to figure out what to do with it. In the example above, we make a new geojson object.
Similar methods are provided for block groups and blocks, for the ACS 5-year and Decennial Census.
c.acs5.geo_blockgroup(('NAME', 'B25034_010E'), my_shape_geojson['geometry']) c.sf1.geo_block(('NAME', 'H016F0002'), my_shape_geojson['geometry']) c.sf1.geo_blockgroup(('NAME', 'H016F0002'), my_shape_geojson['geometry']) c.sf1.geo_tract(('NAME', 'H016F0002'), my_shape_geojson['geometry']) c.sf3.state_place_tract('NAME', 'H034010'), my_shape_geojson['geometry']) c.sf3.state_place_blockgroup('NAME', 'H034010'), my_shape_geojson['geometry'])
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 census_area-0.1.tar.gz
.
File metadata
- Download URL: census_area-0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64dbdb12cb0242b31b7e03f67baa2dc50f76339952865e748d19fa1770eaa7b2 |
|
MD5 | 62d6af55f18f657e8d925d170397503b |
|
BLAKE2b-256 | e28a17da2c9b83ca4de46dea200357018dad832468000172217fe56f8bd42e1e |
File details
Details for the file census_area-0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: census_area-0.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf69f1212fa7ab7856bc7eb534ca5bb5eeca96664011c42aed796feb339d58a2 |
|
MD5 | a40065ae4507114e906f3e7298db0036 |
|
BLAKE2b-256 | c5388c83d604811b657a4cd2a88bda70e55c5c37ce7a6afa6f13fd80e382299c |