Explore and download data from Census APIs
Project description
An interface to explore and query the US Census API and return Pandas Dataframes. This package is intended for exploratory data analysis and draws inspiration from sqlalchemy-like interfaces and acs.R. With separate APIs for application developers and folks who only want to get their data quickly & painlessly, cenpy should meet the needs of most who aim to get US Census Data from Python.
A few examples are available from our website:
analyzing segregation over time & across space using cenpy and segregation
a road to frictionless urban data science using cenpy and osmnx
Installation
Cenpy is easiest to install using conda, a commonly-used package manager for scientific python. First, install Anaconda.
Then, cenpy is available on the conda-forge channel:
conda install -c conda-forge cenpy
Alternatively, you can install cenpy via pip, the python package manager, if you have installed geopandas and rtree:
pip install cenpy
For Users
Most of the time, users want a simple and direct interface to the US Census Bureau’s main products: the 2010 Census and the American Community Survey. Fortunately, cenpy provides a direct interface to these products. For instance, the American Community Survey’s most recent 5-year estimates can be accessed using:
import cenpy acs = cenpy.products.ACS() acs.from_place('Chicago, IL')
Likewise, the decennial census can be accessed using:
import cenpy decennial = cenpy.products.Decennial2010() decennial.from_place('Seattle, WA')
For more information on how the product API works, consult the notebook on the topic.
For Developers
The API reference is available at cenpy-devs.github.io/cenpy. The products are typically what most end-users will want to interact with. If you want more fine-grained access to the USCB APIs, you will likely want to build on top of APIConnection and TigerConnection.
To create a connection:
cxn = cenpy.remote.APIConnection('DECENNIALSF12010')
Check the variables required and geographies supported:
cxn.variables #is a pandas dataframe containing query-able vbls cxn.geographies #is a pandas dataframe containing query-able geographies
Note that some geographies (like tract) have higher-level requirements that you’ll have to specify for the query to work.
The structure of the query function maps to the Census API’s use of get, for, and in. The main arguments for the query function are cols, geo_unit and geo_filter, and map back to those predicates, respectively. If more predicates are required for the search, they can be added as keyword arguments at the end of the query.
The cols argument must be a list of columns to retrieve from the dataset. Then, you must specify the geo_unit and geo_filter, which provide what the unit of aggregation should be and where the units should be. geo_unit must be a string containing the unit of analysis and an identifier. For instance, if you want all counties in Arizona, you specify geo_unit = 'county:*' and geo_filter = {'state':'04'}.
ToDo:
A product in cenpy.products for County Business Statistics
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
File details
Details for the file cenpy-1.0.0.post2.tar.gz
.
File metadata
- Download URL: cenpy-1.0.0.post2.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a89f3cd1aba4578c54f9dd2dc83c9d45e6769d67155aa309aa8ca0698abfc19 |
|
MD5 | a0d67723f6a05e26bbb238f624551970 |
|
BLAKE2b-256 | 29baf7937219c3372bd0d623470cc1b50317a63f6e247daf71a04e7e1614a0cb |