Skip to main content

Explore and download data from Census APIs

Project description

https://travis-ci.org/ljwolf/cenpy.svg?branch=master https://img.shields.io/pypi/dm/cenpy.svg https://zenodo.org/badge/36956226.svg

An interface to explore and query the US Census API and return Pandas Dataframes. Ideally, this package is intended for exploratory data analysis and draws inspiration from sqlalchemy-like interfaces and acs.R.

An intro notebook is available.

Also, a great example on how to grab work with cenpy, moving from nothing to data to map, is here, by @dfolch.

Installation

This package depends on Pandas and requests. You can install cenpy and other dependencies using pip:

pip install cenpy

If you do not have pip, simply copy the module somewhere in your python path.

Usage

Once done, importing cenpy will provide the explorer and base modules. To create a connection:

cxn = cenpy.base.Connection('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:

  • Recursively search for incompletely-specified hierarchies (partially implemented in cenpy.tools)

  • Write dedicated wrappers for commonly-used data products, such as
    • ACS

    • Decennial censuses (2010,2000,1990)

    • County Business Statistics

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

cenpy-1.0.0rc1.tar.gz (43.3 kB view details)

Uploaded Source

File details

Details for the file cenpy-1.0.0rc1.tar.gz.

File metadata

  • Download URL: cenpy-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for cenpy-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 b216e5c0112c21d4ef53c41a7029c1c21ec4159c1b88c9f73d2b379769fc3f3e
MD5 2abb80c0a8e6583f36962e42ed7e8b4c
BLAKE2b-256 dbc65c7921c03f8b84accd566ef9bee9751440dd4477d182919003f6c5ce6606

See more details on using hashes here.

Supported by

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