Giter VIP home page Giter VIP logo

cenpy's Introduction

CenPy

image

image

image

image

image

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:

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.

At a high level, the APIConnection object connects to resources exposed on the US Census Bureau's API at https://api.census.gov/data.json. Its methods and relevant utilities are defined in cenpy.remote. The TigerConnection wraps one map service exposed at http://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb and is defined in cenpy.tiger. Each TigerConnection is composed of many ESRILayer objects, which wrap an individual geography within the ESRI map service. For instance, an ACS TigerConnection may contain State, County, and Tract ESRILayer objects within their layer attribute.

To use the developer-focused API, you can create an APIConnection using its shortcode:

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 requirements higher in the hierarchy 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'}.

To create a TigerConnection:

cxn = cenpy.tiger.TigerConnection('tigerWMS_ACS2013')

Then, all of the ESRILayer objects are contained in the layer attribute:

cxn.layers

the cxn.query method passes the relevant query down to the chosen layer and returns a geopandas dataframe. The actual query is structured like SQL, and follows the ESRI documentation.

Contributing

To contribute to cenpy:

  1. Use cenpy! Every user is a contributor in kind. If you feel like it, file an issue:
    • to tell us how you use cenpy.
    • to post a code snippit, a jupyter notebook, or whatever you can.
    • to tell us about your blog posts!
    • to ask questions about how you might use census data from Python, and we'll try to help.
  2. If you're using cenpy and something goes wrong, file an issue telling us:
    • what you want that is not in cenpy or doesn't work well in other packages
    • what functionality in cenpy isn't working how you believe it ought
    • what in the documentation isn't spelled correctly or is confusing
  3. Fork the cenpy-devs/cenpy github repository, make changes, and send us a pull request

ToDo:

  • A product in cenpy.products for County Business Statistics

cenpy's People

Contributors

dfolch avatar dmitrytorba avatar geoffrey-eisenbarth avatar joegermuska avatar ljwolf avatar maxghenis avatar sjsrey avatar stuartlynn avatar weikang9009 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.