US Census utilities for a variety of data loading and mapping purposes.
Project description
censusdis
Introduction
censusdis
is a package for discovering, loading, analyzing, and computing
diversity, integration, and segregation metrics
to U.S. Census demographic data. It is designed to be intuitive and Pythonic,
but give users access to the full collection of data and maps the US Census
publishes via their APIs. Data and maps are returned in familiar
Pandas
and
GeoPandas
formats for easy integration with a wide variety of other Python data
analysis, machine learning, and plotting tools.
Data Loading
The censusdis
data loading capabilities have been tested extensively with data from the
American Community Survey (ACS) 5-year data set.
They also work well with other data sets available via the US Census API.
Maps
'censusdis' can also be used to load geographic data from the US Census for geospatial calculations. Maps for a variety of geographic features as described here can be downloaded and cached locally via Python APIs instead of by manual download from the US Census website.
Additionally, for plotting high quality maps, censusdis
can download
cartographic boundary file data. These are available at various resolutions
and sometimes change from year to year. For example, here is what is
available from the US Census for
2020.
Installation and Getting Started
censusdis
can be installed in any python 3.9+ virtual environment using
pip install censusdis
From there, you can download your first data with something as simple as
import censusdis.data as ced
df_county_names = ced.download_detail(
'acs/acs5',
2020,
['NAME'],
state="*",
county="*"
)
This will return a dataframe of containing the names of all 3,221 counties in the United States as of 2020.
Of course, there is far more you can do with censusdis
than this. We encourage
you to check out the sample notebooks
provided with the project for more complete examples.
Modules
The modules that make up the censusdis
package are
Module | Description |
---|---|
censusdis.geography |
Code for managing geography hierarchies in which census data is organized. |
censusdis.data |
Code for fetching data from the US Census API, including managing datasets, groups, and variable hierarchies. |
censusdis.maps |
Code for downloading map data from the US, caching it locally, and using it to render maps. |
censusdis.states |
Constants defining the US States. Used by the three other modules. |
Demonstration Notebooks
There are several demonstration notebooks available to illustrate how censusdis
can
be used. They are found in the
notebook
directory of the source code.
The notebooks include
Notebook Name | Description |
---|---|
SoMa DIS Demo.ipynb | Load race and ethnicity data for two towns in Essex County, NJ and compute diversity and integration metrics. |
ACS Demo.ipynb | Load American Community Survey (ACS) data for New Jersey and plot diversity statewide at the census block group level. |
PUMS Demo.ipynb | Load Public-Use Microdata Samples (PUMS) data for Massachusetts and plot it. |
Seeing White.ipynb | Load nationwide demographic data at the county level and plot of map of the US showing the percent of the population who identify as white only (no other race) at the county level. |
Map Demo.ipynb | Demonstrate loading at plotting maps of New Jersey at different geographic granularity. |
Exploring Variables.ipynb | Load metatdata on a group of variables, visualize the tree hierarchy of variables in the group, and load data from the leaves of the tree. |
Diversity and Integration Metrics
Diversity and integration metrics from the divintseg
package are
demonstrated in some notebooks.
For more information on these metrics see the divintseg project.
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
Hashes for censusdis-0.7.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cc696595b2ccf8909bf638538b157b6b2f94c13e5c923f8731490ad98d49930 |
|
MD5 | cd23c5fbbadae27e68f4ce8aaf9f6604 |
|
BLAKE2b-256 | f650bf934dfceb481c224b59b786520eaa4e2a26fbf812348b10e63547c32cb6 |