Examples and Tutorials
This section contains Jupyter notebook examples that demonstrate the key features of pytidycensus. These notebooks are Python ports of the original tidycensus R vignettes, adapted for the Python ecosystem.
Getting Started
All examples require a free Census API key. Get one at: https://api.census.gov/data/key_signup.html
To run these notebooks locally:
pip install pytidycensus matplotlib seaborn jupyter
jupyter notebook examples/
Basic Usage
Learn the fundamentals of accessing Census data with pytidycensus:
- Setting up your Census API key 
- Using - get_decennial()and- get_acs()functions
- Understanding data formats (tidy vs wide) 
- Working with different geographic levels 
- Searching for variables 
Time Series Data
Analyze trends over time with ACS data: * Fetching multi-year ACS data * Visualizing changes in demographics * Handling variable availability across years * Creating time series plots with matplotlib and seaborn
Spatial Data and Mapping
Explore mapping and spatial analysis capabilities:
- Retrieving Census data with geometry 
- Creating choropleth maps with matplotlib and geopandas 
- Faceted mapping for multiple variables 
- Working with coordinate reference systems 
- Spatial data visualization best practices 
- Interactive migration flow visualization with BrushingExtension (09_flow_brushmap_api) 
Margins of Error
Understanding uncertainty in American Community Survey data:
- Working with estimates and margins of error 
- Visualizing uncertainty in data 
- Aggregating estimates and calculating derived margins of error 
- Using margin of error functions for proper statistical analysis 
Other Census Datasets
Accessing additional Census datasets:
- Population Estimates Program data with - get_estimates()
- Migration flows data with - get_flows()
- Components of population change 
- Housing estimates and characteristics 
For interactive migration flow visualization, see the Flow Brushmap API example in the Spatial Data and Mapping section above.
Census Microdata
Advanced analysis with Public Use Microdata Sample (PUMS):
- Understanding microdata vs. aggregated data 
- Working with Public Use Microdata Areas (PUMAs) 
- Using survey weights for proper statistical inference 
- Creating custom estimates from individual-level data 
Additional Resources
Running Examples Online
All examples include “Open in Colab” badges for easy execution in Google Colab without local installation.
Contributing Examples
Have an interesting use case or analysis? We welcome contributions of additional examples:
- Create a new Jupyter notebook following the existing format 
- Add descriptive markdown cells explaining the analysis 
- Include proper citations and data sources 
- Submit a pull request to the repository 
For questions or suggestions about the examples, please open an issue on GitHub.
Come study with us at The George Washington University
