Giter VIP home page Giter VIP logo

cenpy's Introduction

CenPy

image

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('2010sf1')

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 backwards 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
  • [ ] Document commonly-used data resources (like tract_to_block in cenpy.tools).

cenpy's People

Contributors

ljwolf avatar joegermuska avatar dmitrytorba avatar geoffrey-eisenbarth avatar dfolch avatar

Watchers

KG 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.