{
"cells": [
{
"cell_type": "markdown",
"id": "8bb25ba4-698b-466b-89d3-52a3f6808b54",
"metadata": {},
"source": [
"## United States 2020 Census data\n",
"\n",
"In this tutorial, you will explore various subsets of geographic data in the [United States 2020 Census](https://www.census.gov/programs-surveys/decennial-census/decade/2020/2020-census-main.html). You will learn how the data is structured and how to access the data.\n",
"\n",
"The data consists of two groups:\n",
"1. **Census data by census block boundaries**: This group contains data for each census block, grouped by US counties. Census blocks are the smallest available unit made available by the US Census Bureau. This group also includes population totals broken down by census block, available in a second table.\n",
"2. **Census data by cartographic boundaries**: This group contains data that is aggregated by 29 different geographic boundaries, ranging from block groups to regional datasets such as metropolitan divisions and states. This group does not include any demographic information.\n",
"\n",
"This notebook contains details about all geographic datasets within the 2020 census data. Use the table of contents to jump to any section relevant to you. For a brief introduction, [Accessing US Census data with the Planetary Computer STAC API](../datasets/us-census/us-census-example.ipynb).\n",
"\n",
"### Table of Contents\n",
"\n",
"* [Accessing the Data](#Accessing-the-Data)\n",
"* [Import Dependencies](#Import-Dependencies)\n",
"* [Census data by census block boundaries](#Census-data-by-census-block-boundaries)\n",
" * [Census Block Boundaries](#Census-Block-Boundaries) (8,180,866 features)\n",
"* [Census data by cartographic boundaries](#Census-data-by-cartographic-boundaries)\n",
" * [American Indian Area Geographies](#American-Indian-Area-Geographies)\n",
" * [American Indian/Alaska Native Areas/Hawaiian Home Lands](#American-Indian/Alaska-Native-Areas/Hawaiian-Home-Lands-(AIANNH)) (704 features)\n",
" * [American Indian Tribal Subdivisions](#American-Indian-Tribal-Subdivisions-(AITSN)) (484 features)\n",
" * [Alaska Native Regional Corporations](#Alaska-Native-Regional-Corporations-(ANRC)) (12 features)\n",
" * [Tribal Block Groups](#Tribal-Block-Groups-(TBG)) (934 features)\n",
" * [Tribal Census Tracts](#Tribal-Census-Tracts-(TTRACT)) (492 features)\n",
" * [Census Block Groups](#Census-Block-Groups-(BG)) (242,305 features)\n",
" * [Census Tracts](#Census-Tracts-(TRACT)) (85,190 features)\n",
" * [Congressional Districts](#Congressional-Districts:-116th-Congress-(CD116)) (441 features)\n",
" * [Consolidated Cities](#Consolidated-Cities-(CONCITY)) (8 features)\n",
" * [Counties](#Counties-(COUNTY)) (3,234 features)\n",
" * [Counties within Congressional Districts](#Counties-within-Congressional-Districts:-116th-Congress-(COUNTY_within_CD116)) (3,836 features)\n",
" * [County Subdivisions](#County-Subdivisions-(COUSUB)) (36,502 features)\n",
" * [Divisions](#Divisions-(DIVISION)) (9 features)\n",
" * [Metropolitan and Micropolitan Statistical Areas and Related Statistical Areas](#Metropolitan-and-Micropolitan-Statistical-Areas-and-Related-Statistical-Areas)\n",
" * [Core Based Statistical Areas](#Core-Based-Statistical-Areas-(CBSA)) (939 features)\n",
" * [Combined Statistical Areas](#Combined-Statistical-Areas-(CSA)) (175 features)\n",
" * [Metropolitan Divisions](#Metropolitan-Divisions-(METDIV)) (31 features)\n",
" * [New England City and Town Areas](#New-England-City-and-Town-Areas-(NECTA)) (40 features)\n",
" * [New England City and Town Areas Division](#New-England-City-and-Town-Areas-Division(NECTADIV)) (11 features)\n",
" * [Combined New England City and Town Areas](#Combined-New-England-City-and-Town-Areas-(CNECTA)) (7 features)\n",
" * [Places](#Places-(PLACE)) (32,188 features)\n",
" * [Regions](#Regions-(REGION)) (4 features)\n",
" * [School Districts](#School-Districts)\n",
" * [Elementary](#School-Districts---Elementary-(ELSD)) (1,945 features)\n",
" * [Secondary](#School-Districts---Secondary-(SCSD)) (473 features)\n",
" * [Unified](#School-Districts---Unified-(UNSD)) (10,867 features)\n",
" * [State Legislative Districts](#State-Legislative-Districts)\n",
" * [Lower Chamber](#State-Legislative-Districts---Lower-Chamber-(SLDL)) (4,829 features)\n",
" * [Upper Chamber](#State-Legislative-Districts---Upper-Chamber-(SLDU)) (1,958 features)\n",
" * [States](#States-(STATE)) (56 features)\n",
" * [Subbarrios](#Subbarrios-(SUBBARRIO)) (145 features)\n",
" * [United States Outline](#United-States-Outline) (1 feature)\n",
" * [Voting Districts](#Voting-Districts-(VTD)) (158,320 features)\n",
"\n",
"### Accessing the Data\n",
"\n",
"Like other datasets on the Planetary Computer, US Census datasets are cataloged using [STAC](https://stacspec.org/). Each table, corresponding a particular level of cartographic aggregation, is available as a STAC item under the `us-census` collection."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "27f8a592-1b81-49ed-a06a-731119df9113",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
"
\n",
" type\n",
" \"Collection\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" id\n",
" \"us-census\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" stac_version\n",
" \"1.0.0\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"The [2020 Census](https://www.census.gov/programs-surveys/decennial-census/decade/2020/2020-census-main.html) counted every person living in the United States and the five U.S. territories. It marked the 24th census in U.S. history and the first time that households were invited to respond to the census online.\n",
"\n",
"The tables included on the Planetary Computer provide information on population and geographic boundaries at various levels of cartographic aggregation.\n",
"\"\n",
"
\n",
" description\n",
" \"This file contains data for legal and statistical [American Indian/Alaska Native Areas/Hawaiian Home Lands (AIANNH)](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_1) entities published by the US Census Bureau.\"\n",
"
\n",
" name\n",
" \"American Indian Tribal Subdivisions (AITSN)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains data on [American Indian Tribal Subdivisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_1). These areas are the legally defined subdivisions of American Indian Reservations (AIR), Oklahoma Tribal Statistical Areas (OTSA), and Off-Reservation Trust Land (ORTL).\"\n",
"
\n",
" description\n",
" \"This file contains data on [Alaska Native Regional Corporations](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_1), which are corporations created according to the Alaska Native Claims Settlement Act. \"\n",
"
\n",
" name\n",
" \"Tribal Block Groups (TBG)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file includes data on [Tribal Block Groups](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_26), which are subdivisions of Tribal Census Tracts. These block groups can extend over multiple AIRs and ORTLs due to areas not meeting Block Group minimum population thresholds.\"\n",
"
\n",
" name\n",
" \"Tribal Census Tracts (TTRACT)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file includes data on [Tribal Census Tracts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_27) which are relatively small statistical subdivisions of AIRs and ORTLs defined by federally recognized tribal government officials in partnership with the Census Bureau. Due to population thresholds, the Tracts may consist of multiple non-contiguous areas.\"\n",
"
\n",
" name\n",
" \"Census Block Groups (BG)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains data on [Census Block Groups](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_4). These groups are the second smallest geographic grouping. They consist of clusters of blocks within the same census tract that share the same first digit of their 4-character census block number. Census Block Groups generally contain between 600 and 3,000 people and generally cover contiguous areas.\"\n",
"
\n",
" description\n",
" \"This file contains data on [Census Tracts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_13) which are small and relatively permanent statistical subdivisions of a county or equivalent entity. Tract population size is generally between 1,200 and 8,000 people with an ideal size of 4,000. Boundaries tend to follow visible and identifiable features and are usually contiguous areas.\"\n",
"
\n",
" name\n",
" \"Congressional Districts: 116th Congress (CD116)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains data on the [Congressional Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_9) for the 116th Congress. \"\n",
"
\n",
" description\n",
" \"This file contains data on [Consolidated Cities](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_8). These are areas where one or several other incorporated places in a county or Minor Civil Division are included in a consolidated government but still exist as separate legal entities.\"\n",
"
\n",
" description\n",
" \"This file contains data on [Counties and Equivalent Entities](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_12). These are the primary legal divisions of states. Most states use the term \"counties,\" but other terms such as \"Parishes,\" \"Municipios,\" or \"Independent Cities\" may be used. \"\n",
"
\n",
" description\n",
" \"This file contains [County Subdivisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_11), which are the primary divisions of counties and equivalent entities. These divisions vary from state to state and include Barrios, Purchases, Townships, and other types of legal and statistical entities. \"\n",
"
\n",
" description\n",
" \"This file contains data on [Divisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_10) of the US. This file is similar to the Regions file but contains more divisions and encompasses several states per division.\"\n",
"
\n",
" name\n",
" \"Core Based Statistical Areas (CBSAs)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains data on [Core Based Statistical Areas (CBSAs)](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7). This encompasses all metropolitan and micropolitan statistical areas.\"\n",
"
\n",
" name\n",
" \"Combined Statistical Areas (CSA)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains data on [Combined Statistical Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), which are areas that consist of two or more adjacent CBSAs that have significant employment interchanges.\"\n",
"
\n",
" description\n",
" \"This file contains data on [Metropolitan Divisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7). These areas are groupings of counties or equivalent entities within a metropolitan statistical area with a core of 2.5 million inhabitants and one or more main counties that represent employment centers, plus adjacent counties with commuting ties.\"\n",
"
\n",
" name\n",
" \"New England City and Town Areas (NECTA)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains [New England City and Town Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), which encompass metropolitan and micropolitan statistical areas and urban clusters in New England.\"\n",
"
\n",
" name\n",
" \"New England City and Town Area Division (NECTADIV)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains [New England City and Town Areas Divisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), which are smaller groupings of cities and towns in New England that contain a single core of 2.5 million inhabitants. Each division must have a total population of 100,000 or more.\"\n",
"
\n",
" name\n",
" \"Combined New England City and Town Areas (CNECTA)\"\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
\n",
" description\n",
" \"This file contains data on [Combined New England City and Town Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), consisting of two or more adjacent NECTAs that have significant employment interchanges.\"\n",
"
\n",
" description\n",
" \"This file contains [Places](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_14) which are Incorporated Places (legal entities) and Census Designated Places (CDPs, statistical entities). An incorporated place usually is a city, town, village, or borough but can have other legal descriptions. CDPs are settled concentrations of population that are identifiable by name but are not legally incorporated.\"\n",
"
\n",
" description\n",
" \"This file contains [Regions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_10) of the US and encompasses several states per division.\"\n",
"
\n",
" description\n",
" \"This file contains [Unified School Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_23), referring to districts that provide education to children of all school ages. Unified school districts can have both secondary and elementary schools.\"\n",
"
\n",
" description\n",
" \"This file contains the [US States and State Equivalent Entities](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_25). Within Census Bureau datasets, the District of Columbia, Puerto Rico, and the Island Areas (American Samoa, the Commonwealth of the Northern Mariana Islands, Guam, and the US Virgin Islands) are treated as statistical equivalents of states alongside the 50 US states.\"\n",
"
\n",
" description\n",
" \"This file contains [Subbarrios](https://www.census.gov/programs-surveys/geography/about/glossary.html#pr), which are legally defined subdivisions of Minor Civil Division in Puerto Rico. They don\"t exist within every Minor Civil Division and don\"t always cover the entire Minor Civil Division where they do exist.\"\n",
"
\n",
" description\n",
" \"This file contains the [United States Outline](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_30) shapefile. This contains all 50 US states plus the District of Columbia, Puerto Rico, and the Island Areas (American Samoa, the Commonwealth of the Northern Mariana Islands, Guam, and the US Virgin Islands). There is only one feature within this dataset.\"\n",
"
\n",
" description\n",
" \"This file contains all [US Voting Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_31), which are geographic features established by state, local and tribal governments to conduct elections.\"\n",
"
"
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pystac_client\n",
"import planetary_computer\n",
"\n",
"catalog = pystac_client.Client.open(\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1/\",\n",
" modifier=planetary_computer.sign_inplace,\n",
")\n",
"census = catalog.get_collection(\"us-census\")\n",
"census"
]
},
{
"cell_type": "markdown",
"id": "61d331c9-be0b-488a-b2e8-17cf9fb49d44",
"metadata": {},
"source": [
"The actual files themselves are stored as [Apache Parquet](https://parquet.apache.org/) datasets in Azure Blob Storage. These files can be loaded with pandas or geopandas, or dask-geopandas if the files are larger than memory.\n",
"\n",
"Loading each of the tables will follow the same basic pattern:\n",
"\n",
"1. Get the Item from the collection with `census.get_item(item_id)`\n",
"2. Use the `href` and `table:storage_options` fields from the `data` asset to load the data with `read_parquet`."
]
},
{
"cell_type": "markdown",
"id": "fb3fad76",
"metadata": {},
"source": [
"### Import Dependencies\n",
"\n",
"We'll import a few libraries to use for accessing and plotting the data. In particular,[geopandas](https://geopandas.org/) and [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to load the parquet datasets and [contextily](https://github.com/geopandas/contextily). Before getting started, make sure you have these two dependencies installed and imported:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "69f74280",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import geopandas\n",
"import dask_geopandas\n",
"import contextily as ctx\n",
"import planetary_computer"
]
},
{
"cell_type": "markdown",
"id": "436d6ded",
"metadata": {},
"source": [
"### Census data by census block boundaries\n",
"\n",
"The first block of data is organized by [Census blocks](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_5). Census blocks are the smallest geographic grouping available in the current dataset. There are over eight million census blocks, resulting in large datasets. To facilitate parallelism and accessing subsets of the data, the Census block-level data are partitioned by state.\n",
"\n",
"There are two tables available at the Census block level: \"geo\", containing the boundaries and other data about the block, and \"population\", containing the population counts in that geometry by various features.\n",
"\n",
"**geo**\n",
"\n",
"* GEOID = Concatenation of county FIPS code, census tract code, and census block number. *In pandas and Dask, this is used as the index*.\n",
"* STATEFP = State FIPS code\n",
"* COUNTYFP = County FIPS code\n",
"* TRACTCE = Census Tract code\n",
"* BLOCKCE = Census Block code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* INTPTLAT = Current latitude of the internal point\n",
"* INTPTLON = Current longitude of the internal point\n",
"* geometry = Coordinates for block polygons"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9dbb83a0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
Dask DataFrame Structure:
\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
TRACTCE
\n",
"
BLOCKCE
\n",
"
ALAND
\n",
"
AWATER
\n",
"
INTPTLAT
\n",
"
INTPTLON
\n",
"
geometry
\n",
"
\n",
"
\n",
"
npartitions=56
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
"
\n",
" \n",
" \n",
"
\n",
"
010010201001000
\n",
"
category[unknown]
\n",
"
category[unknown]
\n",
"
int64
\n",
"
int64
\n",
"
int64
\n",
"
int64
\n",
"
float64
\n",
"
float64
\n",
"
geometry
\n",
"
\n",
"
\n",
"
020130001001000
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
\n",
"
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
\n",
"
\n",
"
780109701001000
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
\n",
"
\n",
"
780309900000008
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
...
\n",
"
\n",
" \n",
"
\n",
"
Dask Name: readparquetfsspec, 1 expression
"
],
"text/plain": [
"Dask DataFrame Structure:\n",
" STATEFP COUNTYFP TRACTCE BLOCKCE ALAND AWATER INTPTLAT INTPTLON geometry\n",
"npartitions=56 \n",
"010010201001000 category[unknown] category[unknown] int64 int64 int64 int64 float64 float64 geometry\n",
"020130001001000 ... ... ... ... ... ... ... ... ...\n",
"... ... ... ... ... ... ... ... ... ...\n",
"780109701001000 ... ... ... ... ... ... ... ... ...\n",
"780309900000008 ... ... ... ... ... ... ... ... ...\n",
"Dask Name: readparquetfsspec, 1 expression\n",
"Expr=ReadParquetFSSpec(2c201cc)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-census-blocks-geo\").assets[\"data\"]\n",
"\n",
"geo = dask_geopandas.read_parquet(\n",
" asset.href,\n",
" storage_options=asset.extra_fields[\"table:storage_options\"],\n",
" calculate_divisions=True,\n",
")\n",
"geo"
]
},
{
"cell_type": "markdown",
"id": "60b0b30b",
"metadata": {},
"source": [
"**pop**\n",
"\n",
"The population table contains may columns. Two are important to call out:\n",
"\n",
"* GEOID = Concatenation of county FIPS code, census tract code, and census block number. *In pandas and Dask, this is used as the index*.\n",
"* P0010001 = Total Block Population\n",
"\n",
"The remainder of the columns provide the Block's population faceted by various features. [This document (pdf)](https://www2.census.gov/programs-surveys/decennial/2010/technical-documentation/complete-tech-docs/summary-file/nsfrd.pdf) documents the meaning of all the additional variables."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e94a7420",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ax = ri.to_crs(epsg=3857).plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Census Blocks: Rhode Island\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "9df40551",
"metadata": {},
"source": [
"Both the geo and population tables use `GEOID` as a unique identifier, so the geometries and population data can be joined together. Remember that population data are not available for territories, so we'll use an inner join."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ac89a359",
"metadata": {},
"outputs": [],
"source": [
"ri = (\n",
" geo.get_partition(39)\n",
" .compute()\n",
" .join(pop[[\"P0010001\"]].get_partition(39).compute(), how=\"inner\")\n",
")\n",
"ri = ri[ri.P0010001 > 10]"
]
},
{
"cell_type": "markdown",
"id": "d3b04ba6",
"metadata": {},
"source": [
"Now lets plot the census blocks in Providence County with at least 150 people."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "06e238f2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"providence = ri[(ri.P0010001 >= 150) & (ri.COUNTYFP == \"007\")]\n",
"\n",
"ax = providence.to_crs(epsg=3857).plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Census Blocks with Population Greater than 150: Providence County, RI\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "41152424",
"metadata": {},
"source": [
"You can use this method with any census block within any county in the US.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**"
]
},
{
"cell_type": "markdown",
"id": "eeb56385",
"metadata": {},
"source": [
"### Census data by cartographic boundaries\n",
"\n",
"The second block of data is organized by different cartographic categories. These boundaries cover larger areas than the individual census blocks discussed [above](#Census-data-by-census-block-boundaries). The different categories range from census block groups (consisting of several census blocks) all the way up to a National Boundary file (encompassing the entire USA).\n",
"\n",
"The files in this second group tend to be smaller in size than the census block data in the first group. Therefore, the files in the second group are not partitioned into multiple files, and each dataset only consists of one parquet file. Another difference is that the datasets in this second group include different information than the census block files in the first group and do not contain population statistics. Which additional data is included differs from dataset to dataset. See [Appendix E. in the 2020 TIGER/Line Technical Documentation](https://www2.census.gov/geo/pdfs/maps-data/data/tiger/tgrshp2020/TGRSHP2020_TechDoc.pdf) for more details on the available feature classes.\n",
"\n",
"The following sections are examples of how to access and view each cartographic boundary file in this second group of data. Each example uses the same basic workflow and dependencies as the [Census Block Boundaries](#Census-data-by-census-block-boundaries) for the first group of data. An important thing to note when using this data is that before plotting the data onto a basemap, the datasets need to be converted to Web Mercator [(EPSG 3857)](https://epsg.io/3857) using the [to_crs](https://geopandas.org/docs/reference/api/geopandas.GeoDataFrame.to_crs.html) function of [GeoPandas](https://geopandas.org/).\n",
"\n",
"Some of the datasets are grouped together based on their type. It is important to note that some of the files may have gaps where no relevant data exists because states with no Tribal Block Groups do not have any Tribal Block Group data. The header for each example also includes the relevant abbreviation used for data access and retrieval.\n",
"\n",
"### American Indian Area Geographies\n",
"\n",
"American Indian Area Geographies is the first grouping of cartographic boundary files available.\n",
"\n",
"#### American Indian/Alaska Native Areas/Hawaiian Home Lands (AIANNH)\n",
"\n",
"This file contains data for legal and statistical [American Indian/Alaska Native Areas/Hawaiian Home Lands (AIANNH)](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_1) entities published by the US Census Bureau.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* AIANNHCE = AIANNH census code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = concatenation of AIANNH census code and reservation/statistical area or off-reservation trust land Hawaiian home land indicator\n",
"* NAME = Current Area Name\n",
"* NAMELSAD = Current name and legal/statistical status for each entity\n",
"* LSAD = Current legal/statistical area code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for AIANNH polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the AIANNH data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "b510cd26-90a0-4d47-ba87-b805e0d839a8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
AIANNHCE
\n",
"
AIANNHNS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
9515
\n",
"
2418775
\n",
"
2500000US9515
\n",
"
9515
\n",
"
Apache Choctaw
\n",
"
Apache Choctaw SDTSA
\n",
"
92
\n",
"
221751364
\n",
"
2632531
\n",
"
POLYGON ((-93.77547 31.61937, -93.77411 31.619...
\n",
"
\n",
"
\n",
"
1
\n",
"
9370
\n",
"
979494
\n",
"
2500000US9370
\n",
"
9370
\n",
"
Shinnecock
\n",
"
Shinnecock (state) Reservation
\n",
"
86
\n",
"
3494292
\n",
"
0
\n",
"
POLYGON ((-72.44070 40.87749, -72.43870 40.879...
\n",
"
\n",
"
\n",
"
2
\n",
"
9820
\n",
"
2418693
\n",
"
2500000US9820
\n",
"
9820
\n",
"
MaChis Lower Creek
\n",
"
MaChis Lower Creek SDTSA
\n",
"
92
\n",
"
1680767035
\n",
"
6816074
\n",
"
MULTIPOLYGON (((-85.54654 31.21440, -85.54342 ...
\n",
"
\n",
"
\n",
"
3
\n",
"
6125
\n",
"
2418774
\n",
"
2500000US6125
\n",
"
6125
\n",
"
Anvik
\n",
"
Anvik ANVSA
\n",
"
79
\n",
"
24578643
\n",
"
6308736
\n",
"
POLYGON ((-160.24545 62.69478, -160.24517 62.6...
\n",
"
\n",
"
\n",
"
4
\n",
"
6350
\n",
"
2418836
\n",
"
2500000US6350
\n",
"
6350
\n",
"
Circle
\n",
"
Circle ANVSA
\n",
"
79
\n",
"
274634016
\n",
"
1398608
\n",
"
POLYGON ((-144.38284 65.73496, -144.37907 65.7...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" AIANNHCE AIANNHNS AFFGEOID GEOID NAME \\\n",
"0 9515 2418775 2500000US9515 9515 Apache Choctaw \n",
"1 9370 979494 2500000US9370 9370 Shinnecock \n",
"2 9820 2418693 2500000US9820 9820 MaChis Lower Creek \n",
"3 6125 2418774 2500000US6125 6125 Anvik \n",
"4 6350 2418836 2500000US6350 6350 Circle \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 Apache Choctaw SDTSA 92 221751364 2632531 \n",
"1 Shinnecock (state) Reservation 86 3494292 0 \n",
"2 MaChis Lower Creek SDTSA 92 1680767035 6816074 \n",
"3 Anvik ANVSA 79 24578643 6308736 \n",
"4 Circle ANVSA 79 274634016 1398608 \n",
"\n",
" geometry \n",
"0 POLYGON ((-93.77547 31.61937, -93.77411 31.619... \n",
"1 POLYGON ((-72.44070 40.87749, -72.43870 40.879... \n",
"2 MULTIPOLYGON (((-85.54654 31.21440, -85.54342 ... \n",
"3 POLYGON ((-160.24545 62.69478, -160.24517 62.6... \n",
"4 POLYGON ((-144.38284 65.73496, -144.37907 65.7... "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_aiannh_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "eebc0042",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and apply a basemap. Rather than displaying the whole dataset, show only the Apache Choctaw American Indian Homeland by selecting a subset of the dataframe where the values in the `NAME` column match `\"Apache Choctaw\"`."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "cdfbc7a7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"Apache Choctaw\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Apache Choctaw American Indian Home Land\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "9eee53ca",
"metadata": {},
"source": [
"This map shows the shape of the Apache Choctaw American Indian Homeland overlaid on a Stamen Terrain Style basemap. To display the entire dataset, remove the part of the code that limits the dataframe to only the Apache Choctaw homeland. To plot a different area, change the dataframe's filter to a different attribute or value.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### American Indian Tribal Subdivisions (AITSN)\n",
"\n",
"This file contains data on [American Indian Tribal Subdivisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_1). These areas are the legally defined subdivisions of American Indian Reservations (AIR), Oklahoma Tribal Statistical Areas (OTSA), and Off-Reservation Trust Land (ORTL).\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* AIANNHCE = AIANNH census code\n",
"* TRSUBCE = Current AITSN census code\n",
"* TRSUBNS = ANSI feature code for American Indian Tribal Subdivision\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = concatenation of AIANNH census code and AITSN census code\n",
"* NAME = Current Area Name\n",
"* NAMELSAD = Current name and legal/statistical AITSN description\n",
"* LSAD = Current legal/statistical area code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for AITSN polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the AIANNH data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "1c74dc98",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf.plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"American Indian Tribal Subdivisions\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "318cfa2c",
"metadata": {},
"source": [
"The map created shows all the American Indian Tribal Subdivisions.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### Alaska Native Regional Corporations (ANRC)\n",
"\n",
"This file contains data on [Alaska Native Regional Corporations](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_1), which are corporations created according to the Alaska Native Claims Settlement Act. \n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* ANRCFP = ANRC FIPS code\n",
"* ANRCNS = ANSI feature code for Alaska Native Regional Corporation\n",
"* AFFGEOID American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = concatenation of state FIPS code and ANRC FIPS Code\n",
"* NAME = Current area name\n",
"* NAMELSAD = Current name and legal/statistical area description\n",
"* LSAD = Legal/statistical area description code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for ANRC polygon\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the ANRC data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "cc7937a8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
ANRCFP
\n",
"
ANRCNS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
02
\n",
"
9040
\n",
"
2419321
\n",
"
2300000US0209040
\n",
"
0209040
\n",
"
Bristol Bay
\n",
"
Bristol Bay Alaska Native Regional Corporation
\n",
"
77
\n",
"
104110270640
\n",
"
25993444733
\n",
"
MULTIPOLYGON (((-158.15947 56.14452, -158.1537...
\n",
"
\n",
"
\n",
"
1
\n",
"
02
\n",
"
590
\n",
"
2419295
\n",
"
2300000US0200590
\n",
"
0200590
\n",
"
Ahtna
\n",
"
Ahtna Alaska Native Regional Corporation
\n",
"
77
\n",
"
74027413736
\n",
"
1391256190
\n",
"
POLYGON ((-149.38382 63.35746, -148.96463 63.4...
\n",
"
\n",
"
\n",
"
2
\n",
"
02
\n",
"
67940
\n",
"
2419136
\n",
"
2300000US0267940
\n",
"
0267940
\n",
"
Sealaska
\n",
"
Sealaska Alaska Native Regional Corporation
\n",
"
77
\n",
"
91073660613
\n",
"
41754708205
\n",
"
MULTIPOLYGON (((-132.09854 56.07761, -132.0974...
\n",
"
\n",
"
\n",
"
3
\n",
"
02
\n",
"
17140
\n",
"
2418878
\n",
"
2300000US0217140
\n",
"
0217140
\n",
"
Cook Inlet
\n",
"
Cook Inlet Alaska Native Regional Corporation
\n",
"
77
\n",
"
96361403418
\n",
"
20418982039
\n",
"
MULTIPOLYGON (((-150.28586 61.12704, -150.2808...
\n",
"
\n",
"
\n",
"
4
\n",
"
02
\n",
"
9800
\n",
"
2419328
\n",
"
2300000US0209800
\n",
"
0209800
\n",
"
Calista
\n",
"
Calista Alaska Native Regional Corporation
\n",
"
77
\n",
"
142464876475
\n",
"
19389800572
\n",
"
MULTIPOLYGON (((-161.67073 58.56075, -161.6672...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP ANRCFP ANRCNS AFFGEOID GEOID NAME \\\n",
"0 02 9040 2419321 2300000US0209040 0209040 Bristol Bay \n",
"1 02 590 2419295 2300000US0200590 0200590 Ahtna \n",
"2 02 67940 2419136 2300000US0267940 0267940 Sealaska \n",
"3 02 17140 2418878 2300000US0217140 0217140 Cook Inlet \n",
"4 02 9800 2419328 2300000US0209800 0209800 Calista \n",
"\n",
" NAMELSAD LSAD ALAND \\\n",
"0 Bristol Bay Alaska Native Regional Corporation 77 104110270640 \n",
"1 Ahtna Alaska Native Regional Corporation 77 74027413736 \n",
"2 Sealaska Alaska Native Regional Corporation 77 91073660613 \n",
"3 Cook Inlet Alaska Native Regional Corporation 77 96361403418 \n",
"4 Calista Alaska Native Regional Corporation 77 142464876475 \n",
"\n",
" AWATER geometry \n",
"0 25993444733 MULTIPOLYGON (((-158.15947 56.14452, -158.1537... \n",
"1 1391256190 POLYGON ((-149.38382 63.35746, -148.96463 63.4... \n",
"2 41754708205 MULTIPOLYGON (((-132.09854 56.07761, -132.0974... \n",
"3 20418982039 MULTIPOLYGON (((-150.28586 61.12704, -150.2808... \n",
"4 19389800572 MULTIPOLYGON (((-161.67073 58.56075, -161.6672... "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_02_anrc_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "569e997b",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. To make the data work better with the Mercator Projection, exclude part of the dataset from the plot. To do so, limit your dataframe to rows that do not include `\"Aleut\"` in the AIANNHCE column."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "66c0a74b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME != \"Aleut\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Alaska Native Regional Corporations (excluding Aleut)\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "d0f2e77b",
"metadata": {},
"source": [
"The map created shows all the Alaskan Native Regional Corporations except for Aleut.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### Tribal Block Groups (TBG)\n",
"\n",
"This file includes data on [Tribal Block Groups](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_26), which are subdivisions of Tribal Census Tracts. These block groups can extend over multiple AIRs and ORTLs due to areas not meeting Block Group minimum population thresholds.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* AIANNHCE = AIANNH census code\n",
"* TTRACTCE = Tribal Census Tract Code\n",
"* TBLKGPCE = Tribal Block Group letter\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = concatenation of AIANNH census code, trivial census tract code, and tribal block group letter\n",
"* NAMELSAD = Current legal/statistical description and tribal block group letter\n",
"* LSAD = Current legal/statistical area code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Block Group polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Tribal Block Group data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "18ae6242",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
AIANNHCE
\n",
"
TTRACTCE
\n",
"
TBLKGPCE
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
2430
\n",
"
T03700
\n",
"
C
\n",
"
2580000US2430T03700C
\n",
"
2430T03700C
\n",
"
Tribal Block Group C
\n",
"
IB
\n",
"
3945195
\n",
"
0
\n",
"
POLYGON ((-111.26008 36.10715, -111.25910 36.1...
\n",
"
\n",
"
\n",
"
1
\n",
"
20
\n",
"
T00400
\n",
"
B
\n",
"
2580000US0020T00400B
\n",
"
0020T00400B
\n",
"
Tribal Block Group B
\n",
"
IB
\n",
"
1200584
\n",
"
100165
\n",
"
POLYGON ((-116.47052 33.78691, -116.46940 33.7...
\n",
"
\n",
"
\n",
"
2
\n",
"
1150
\n",
"
T00100
\n",
"
C
\n",
"
2580000US1150T00100C
\n",
"
1150T00100C
\n",
"
Tribal Block Group C
\n",
"
IB
\n",
"
654354613
\n",
"
2911122
\n",
"
MULTIPOLYGON (((-108.90981 47.91399, -108.8883...
\n",
"
\n",
"
\n",
"
3
\n",
"
2555
\n",
"
T01000
\n",
"
A
\n",
"
2580000US2555T01000A
\n",
"
2555T01000A
\n",
"
Tribal Block Group A
\n",
"
IB
\n",
"
39634390
\n",
"
4216784
\n",
"
POLYGON ((-75.91155 43.00678, -75.90228 43.006...
\n",
"
\n",
"
\n",
"
4
\n",
"
275
\n",
"
T00100
\n",
"
A
\n",
"
2580000US0275T00100A
\n",
"
0275T00100A
\n",
"
Tribal Block Group A
\n",
"
IB
\n",
"
482651
\n",
"
0
\n",
"
POLYGON ((-122.88954 39.02367, -122.88639 39.0...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" AIANNHCE TTRACTCE TBLKGPCE AFFGEOID GEOID \\\n",
"0 2430 T03700 C 2580000US2430T03700C 2430T03700C \n",
"1 20 T00400 B 2580000US0020T00400B 0020T00400B \n",
"2 1150 T00100 C 2580000US1150T00100C 1150T00100C \n",
"3 2555 T01000 A 2580000US2555T01000A 2555T01000A \n",
"4 275 T00100 A 2580000US0275T00100A 0275T00100A \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 Tribal Block Group C IB 3945195 0 \n",
"1 Tribal Block Group B IB 1200584 100165 \n",
"2 Tribal Block Group C IB 654354613 2911122 \n",
"3 Tribal Block Group A IB 39634390 4216784 \n",
"4 Tribal Block Group A IB 482651 0 \n",
"\n",
" geometry \n",
"0 POLYGON ((-111.26008 36.10715, -111.25910 36.1... \n",
"1 POLYGON ((-116.47052 33.78691, -116.46940 33.7... \n",
"2 MULTIPOLYGON (((-108.90981 47.91399, -108.8883... \n",
"3 POLYGON ((-75.91155 43.00678, -75.90228 43.006... \n",
"4 POLYGON ((-122.88954 39.02367, -122.88639 39.0... "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_tbg_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "cfb35a5a",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for Tribal Block Group A by filtering by the TBLKGPCE column. Due to block group population threshold minimums, Tribal Block Group A spans a large portion of the contiguous United States and is not fully connected."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "61459222",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.TBLKGPCE == \"A\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Tribal Block Group A\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "74623101",
"metadata": {},
"source": [
"The map created shows Tribal Block Group A.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### Tribal Census Tracts (TTRACT)\n",
"\n",
"This file includes data on [Tribal Census Tracts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_27) which are relatively small statistical subdivisions of AIRs and ORTLs defined by federally recognized tribal government officials in partnership with the Census Bureau. Due to population thresholds, the Tracts may consist of multiple non-contiguous areas.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* AIANNHCE = AIANNH census code\n",
"* TTRACTCE = Tribal Census Tract Code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = concatenation of AIANNH census code and tribal census tract code\n",
"* NAME = Tribal Census Tract name\n",
"* NAMELSAD = Current legal/statistical description and tribal census tract name\n",
"* LSAD = Current legal/statistical area code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Tribal Census Tract polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Tribal Block Group data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "5699593e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
AIANNHCE
\n",
"
TTRACTCE
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
990
\n",
"
T00100
\n",
"
2560000US0990T00100
\n",
"
0990T00100
\n",
"
T001
\n",
"
Tribal Census Tract T001
\n",
"
IT
\n",
"
134672514
\n",
"
47477
\n",
"
MULTIPOLYGON (((-83.38715 35.46808, -83.38610 ...
\n",
"
\n",
"
\n",
"
1
\n",
"
3935
\n",
"
T00100
\n",
"
2560000US3935T00100
\n",
"
3935T00100
\n",
"
T001
\n",
"
Tribal Census Tract T001
\n",
"
IT
\n",
"
614259770
\n",
"
20267661
\n",
"
MULTIPOLYGON (((-98.76648 48.00405, -98.76471 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
1160
\n",
"
T00200
\n",
"
2560000US1160T00200
\n",
"
1160T00200
\n",
"
T002
\n",
"
Tribal Census Tract T002
\n",
"
IT
\n",
"
1955706500
\n",
"
421434881
\n",
"
POLYGON ((-102.65466 47.87091, -102.65497 47.8...
\n",
"
\n",
"
\n",
"
3
\n",
"
525
\n",
"
T00100
\n",
"
2560000US0525T00100
\n",
"
0525T00100
\n",
"
T001
\n",
"
Tribal Census Tract T001
\n",
"
IT
\n",
"
4176988
\n",
"
0
\n",
"
MULTIPOLYGON (((-80.89902 34.90259, -80.89470 ...
\n",
"
\n",
"
\n",
"
4
\n",
"
4390
\n",
"
T00100
\n",
"
2560000US4390T00100
\n",
"
4390T00100
\n",
"
T001
\n",
"
Tribal Census Tract T001
\n",
"
IT
\n",
"
1612375179
\n",
"
5684784
\n",
"
POLYGON ((-110.53722 40.44993, -110.53444 40.4...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" AIANNHCE TTRACTCE AFFGEOID GEOID NAME \\\n",
"0 990 T00100 2560000US0990T00100 0990T00100 T001 \n",
"1 3935 T00100 2560000US3935T00100 3935T00100 T001 \n",
"2 1160 T00200 2560000US1160T00200 1160T00200 T002 \n",
"3 525 T00100 2560000US0525T00100 0525T00100 T001 \n",
"4 4390 T00100 2560000US4390T00100 4390T00100 T001 \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 Tribal Census Tract T001 IT 134672514 47477 \n",
"1 Tribal Census Tract T001 IT 614259770 20267661 \n",
"2 Tribal Census Tract T002 IT 1955706500 421434881 \n",
"3 Tribal Census Tract T001 IT 4176988 0 \n",
"4 Tribal Census Tract T001 IT 1612375179 5684784 \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((-83.38715 35.46808, -83.38610 ... \n",
"1 MULTIPOLYGON (((-98.76648 48.00405, -98.76471 ... \n",
"2 POLYGON ((-102.65466 47.87091, -102.65497 47.8... \n",
"3 MULTIPOLYGON (((-80.89902 34.90259, -80.89470 ... \n",
"4 POLYGON ((-110.53722 40.44993, -110.53444 40.4... "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_ttract_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "6f48715e",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for Tribal Census Tract T002 by filtering by the NAME column. Due to census tract population threshold minimums, Tribal Census Tract T002 spans a large portion of the contiguous United States and is not fully connected."
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "1d5dbef0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"T002\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Tribal Census Tract T002\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "336eb01b",
"metadata": {},
"source": [
"The map created shows Tribal Census Tract T002.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Census Block Groups (BG)\n",
"\n",
"This file contains data on [Census Block Groups](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_4). These groups are the second smallest geographic grouping. They consist of clusters of blocks within the same census tract that share the same first digit of their 4-character census block number. Census Block Groups generally contain between 600 and 3,000 people and generally cover contiguous areas.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* COUNTYFP = County FIPS code\n",
"* TRACTCE = Census tract code\n",
"* BLKGRPCE = Block group number\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS, County FIPS, Census tract code, and block group number\n",
"* NAME = Block group number\n",
"* NAMELSAD = Legal/statistical description and group number\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Block Group polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Block Group data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "f93a809d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
TRACTCE
\n",
"
BLKGRPCE
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
36
\n",
"
029
\n",
"
4200
\n",
"
2
\n",
"
1500000US360290042002
\n",
"
360290042002
\n",
"
2
\n",
"
Block Group 2
\n",
"
BG
\n",
"
168802
\n",
"
0
\n",
"
POLYGON ((-78.81870 42.93591, -78.81814 42.936...
\n",
"
\n",
"
\n",
"
1
\n",
"
36
\n",
"
061
\n",
"
12400
\n",
"
8
\n",
"
1500000US360610124008
\n",
"
360610124008
\n",
"
8
\n",
"
Block Group 8
\n",
"
BG
\n",
"
18510
\n",
"
0
\n",
"
POLYGON ((-73.95425 40.76617, -73.95203 40.765...
\n",
"
\n",
"
\n",
"
2
\n",
"
36
\n",
"
059
\n",
"
410400
\n",
"
4
\n",
"
1500000US360594104004
\n",
"
360594104004
\n",
"
4
\n",
"
Block Group 4
\n",
"
BG
\n",
"
305990
\n",
"
0
\n",
"
POLYGON ((-73.72361 40.66781, -73.72217 40.672...
\n",
"
\n",
"
\n",
"
3
\n",
"
36
\n",
"
047
\n",
"
118800
\n",
"
2
\n",
"
1500000US360471188002
\n",
"
360471188002
\n",
"
2
\n",
"
Block Group 2
\n",
"
BG
\n",
"
52033
\n",
"
0
\n",
"
POLYGON ((-73.86754 40.68043, -73.86575 40.680...
\n",
"
\n",
"
\n",
"
4
\n",
"
36
\n",
"
005
\n",
"
12500
\n",
"
1
\n",
"
1500000US360050125001
\n",
"
360050125001
\n",
"
1
\n",
"
Block Group 1
\n",
"
BG
\n",
"
100794
\n",
"
0
\n",
"
POLYGON ((-73.89529 40.82814, -73.89506 40.828...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP COUNTYFP TRACTCE BLKGRPCE AFFGEOID GEOID \\\n",
"0 36 029 4200 2 1500000US360290042002 360290042002 \n",
"1 36 061 12400 8 1500000US360610124008 360610124008 \n",
"2 36 059 410400 4 1500000US360594104004 360594104004 \n",
"3 36 047 118800 2 1500000US360471188002 360471188002 \n",
"4 36 005 12500 1 1500000US360050125001 360050125001 \n",
"\n",
" NAME NAMELSAD LSAD ALAND AWATER \\\n",
"0 2 Block Group 2 BG 168802 0 \n",
"1 8 Block Group 8 BG 18510 0 \n",
"2 4 Block Group 4 BG 305990 0 \n",
"3 2 Block Group 2 BG 52033 0 \n",
"4 1 Block Group 1 BG 100794 0 \n",
"\n",
" geometry \n",
"0 POLYGON ((-78.81870 42.93591, -78.81814 42.936... \n",
"1 POLYGON ((-73.95425 40.76617, -73.95203 40.765... \n",
"2 POLYGON ((-73.72361 40.66781, -73.72217 40.672... \n",
"3 POLYGON ((-73.86754 40.68043, -73.86575 40.680... \n",
"4 POLYGON ((-73.89529 40.82814, -73.89506 40.828... "
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_bg_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "1123b826",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for the state of California by filtering by the State FIPS code (`\"06\"`) in the STATEFP column."
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "67eb60d2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STATEFP == \"06\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Census Block Groups: California\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "03dfccae",
"metadata": {},
"source": [
"The map created shows all the Census Block Groups in California.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Census Tracts (TRACT)\n",
"\n",
"This file contains data on [Census Tracts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_13) which are small and relatively permanent statistical subdivisions of a county or equivalent entity. Tract population size is generally between 1,200 and 8,000 people with an ideal size of 4,000. Boundaries tend to follow visible and identifiable features and are usually contiguous areas.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* COUNTYFP = County FIPS code\n",
"* TRACTCE = Census tract code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS, County FIPS, and Census tract code\n",
"* NAME = Census Tract name, it is the census tract code converted to an integer\n",
"* NAMELSAD = Legal/statistical description and tract name\n",
"* STUSPS = FIPS State Postal Code\n",
"* NAMELSADCO = County name\n",
"* STATE_NAME = State Name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Census Tract polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Census Tract data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "b78bc969",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
TRACTCE
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
STUSPS
\n",
"
NAMELSADCO
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
17
\n",
"
089
\n",
"
853004
\n",
"
1400000US17089853004
\n",
"
17089853004
\n",
"
8530.04
\n",
"
Census Tract 8530.04
\n",
"
IL
\n",
"
Kane County
\n",
"
Illinois
\n",
"
CT
\n",
"
3622334
\n",
"
91650
\n",
"
POLYGON ((-88.35003 41.80764, -88.34938 41.810...
\n",
"
\n",
"
\n",
"
1
\n",
"
11
\n",
"
001
\n",
"
5003
\n",
"
1400000US11001005003
\n",
"
11001005003
\n",
"
50.03
\n",
"
Census Tract 50.03
\n",
"
DC
\n",
"
District of Columbia
\n",
"
District of Columbia
\n",
"
CT
\n",
"
94136
\n",
"
0
\n",
"
POLYGON ((-77.03195 38.90965, -77.03032 38.909...
\n",
"
\n",
"
\n",
"
2
\n",
"
06
\n",
"
037
\n",
"
482503
\n",
"
1400000US06037482503
\n",
"
06037482503
\n",
"
4825.03
\n",
"
Census Tract 4825.03
\n",
"
CA
\n",
"
Los Angeles County
\n",
"
California
\n",
"
CT
\n",
"
729678
\n",
"
0
\n",
"
POLYGON ((-118.09949 34.06262, -118.09466 34.0...
\n",
"
\n",
"
\n",
"
3
\n",
"
31
\n",
"
153
\n",
"
10630
\n",
"
1400000US31153010630
\n",
"
31153010630
\n",
"
106.30
\n",
"
Census Tract 106.30
\n",
"
NE
\n",
"
Sarpy County
\n",
"
Nebraska
\n",
"
CT
\n",
"
4964876
\n",
"
0
\n",
"
POLYGON ((-96.23429 41.19035, -96.23010 41.190...
\n",
"
\n",
"
\n",
"
4
\n",
"
12
\n",
"
057
\n",
"
13706
\n",
"
1400000US12057013706
\n",
"
12057013706
\n",
"
137.06
\n",
"
Census Tract 137.06
\n",
"
FL
\n",
"
Hillsborough County
\n",
"
Florida
\n",
"
CT
\n",
"
535141
\n",
"
10298
\n",
"
POLYGON ((-82.34769 27.89656, -82.34680 27.898...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP COUNTYFP TRACTCE AFFGEOID GEOID NAME \\\n",
"0 17 089 853004 1400000US17089853004 17089853004 8530.04 \n",
"1 11 001 5003 1400000US11001005003 11001005003 50.03 \n",
"2 06 037 482503 1400000US06037482503 06037482503 4825.03 \n",
"3 31 153 10630 1400000US31153010630 31153010630 106.30 \n",
"4 12 057 13706 1400000US12057013706 12057013706 137.06 \n",
"\n",
" NAMELSAD STUSPS NAMELSADCO STATE_NAME \\\n",
"0 Census Tract 8530.04 IL Kane County Illinois \n",
"1 Census Tract 50.03 DC District of Columbia District of Columbia \n",
"2 Census Tract 4825.03 CA Los Angeles County California \n",
"3 Census Tract 106.30 NE Sarpy County Nebraska \n",
"4 Census Tract 137.06 FL Hillsborough County Florida \n",
"\n",
" LSAD ALAND AWATER geometry \n",
"0 CT 3622334 91650 POLYGON ((-88.35003 41.80764, -88.34938 41.810... \n",
"1 CT 94136 0 POLYGON ((-77.03195 38.90965, -77.03032 38.909... \n",
"2 CT 729678 0 POLYGON ((-118.09949 34.06262, -118.09466 34.0... \n",
"3 CT 4964876 0 POLYGON ((-96.23429 41.19035, -96.23010 41.190... \n",
"4 CT 535141 10298 POLYGON ((-82.34769 27.89656, -82.34680 27.898... "
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_tract_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "015f4c06",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for Census Tracts located in Washington, DC by filtering for `\"DC\"` in the STUSPS column."
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "1f08cebb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STUSPS == \"DC\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Census Tracts: Washington, DC\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "3e9da80b",
"metadata": {},
"source": [
"The map created shows all the Census Tracts in Washington, DC.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Congressional Districts: 116th Congress (CD116)\n",
"\n",
"This file contains data on the [Congressional Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_9) for the 116th Congress. \n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS Code\n",
"* CD116FP = Congressional District FIPS code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS and congressional district FIPS code\n",
"* NAMELSAD = Legal/statistical description and name\n",
"* LSAD = Legal/statistical classification\n",
"* CDSESSN = Congressional Session Code\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Congressional District polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Congressional District data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "2bfe3289-6cff-4daf-97eb-d9eb96f9a950",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
CD116FP
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
CDSESSN
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
06
\n",
"
42
\n",
"
5001600US0642
\n",
"
0642
\n",
"
Congressional District 42
\n",
"
C2
\n",
"
116
\n",
"
2424753563
\n",
"
44105315
\n",
"
POLYGON ((-117.67629 33.88882, -117.65488 33.8...
\n",
"
\n",
"
\n",
"
1
\n",
"
39
\n",
"
7
\n",
"
5001600US3907
\n",
"
3907
\n",
"
Congressional District 7
\n",
"
C2
\n",
"
116
\n",
"
10010016396
\n",
"
64562455
\n",
"
MULTIPOLYGON (((-82.55933 40.78975, -82.55835 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
48
\n",
"
3
\n",
"
5001600US4803
\n",
"
4803
\n",
"
Congressional District 3
\n",
"
C2
\n",
"
116
\n",
"
1245574011
\n",
"
97890112
\n",
"
POLYGON ((-96.84410 32.98891, -96.84403 32.992...
\n",
"
\n",
"
\n",
"
3
\n",
"
28
\n",
"
2
\n",
"
5001600US2802
\n",
"
2802
\n",
"
Congressional District 2
\n",
"
C2
\n",
"
116
\n",
"
40278711117
\n",
"
951654563
\n",
"
POLYGON ((-91.36371 31.78036, -91.35951 31.799...
\n",
"
\n",
"
\n",
"
4
\n",
"
42
\n",
"
18
\n",
"
5001600US4218
\n",
"
4218
\n",
"
Congressional District 18
\n",
"
C2
\n",
"
116
\n",
"
757655195
\n",
"
19985421
\n",
"
POLYGON ((-80.17834 40.33725, -80.17537 40.338...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP CD116FP AFFGEOID GEOID NAMELSAD LSAD \\\n",
"0 06 42 5001600US0642 0642 Congressional District 42 C2 \n",
"1 39 7 5001600US3907 3907 Congressional District 7 C2 \n",
"2 48 3 5001600US4803 4803 Congressional District 3 C2 \n",
"3 28 2 5001600US2802 2802 Congressional District 2 C2 \n",
"4 42 18 5001600US4218 4218 Congressional District 18 C2 \n",
"\n",
" CDSESSN ALAND AWATER \\\n",
"0 116 2424753563 44105315 \n",
"1 116 10010016396 64562455 \n",
"2 116 1245574011 97890112 \n",
"3 116 40278711117 951654563 \n",
"4 116 757655195 19985421 \n",
"\n",
" geometry \n",
"0 POLYGON ((-117.67629 33.88882, -117.65488 33.8... \n",
"1 MULTIPOLYGON (((-82.55933 40.78975, -82.55835 ... \n",
"2 POLYGON ((-96.84410 32.98891, -96.84403 32.992... \n",
"3 POLYGON ((-91.36371 31.78036, -91.35951 31.799... \n",
"4 POLYGON ((-80.17834 40.33725, -80.17537 40.338... "
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_cd116_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "9acf6553",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for Maryland\"s 2nd Congressional District by filtering by the State FIPS code `24` and the Congressional District FIPS code `02` in the GEOID column."
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "9e41ef73",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.GEOID == \"2402\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"2nd Congressional District: Maryland\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "b2ea1246",
"metadata": {},
"source": [
"The map created shows Maryland\"s 2nd Congressional District.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Consolidated Cities (CONCITY)\n",
"\n",
"This file contains data on [Consolidated Cities](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_8). These are areas where one or several other incorporated places in a county or Minor Civil Division are included in a consolidated government but still exist as separate legal entities.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS Code\n",
"* CONCTYFP = Consolidated city FIPS code\n",
"* CONCTYNS = Consolidated city GNIS code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS and consolidated city FIPS code\n",
"* NAME = Consolidated city name\n",
"* NAMELSAD = Name and Legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Consolidated City polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Consolidated City data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "948bf82e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
CONCTYFP
\n",
"
CONCTYNS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
20
\n",
"
28410
\n",
"
2664357
\n",
"
1700000US2028410
\n",
"
2028410
\n",
"
Greeley County
\n",
"
Greeley County unified government
\n",
"
UG
\n",
"
2015424640
\n",
"
0
\n",
"
POLYGON ((-102.04526 38.50540, -102.04526 38.5...
\n",
"
\n",
"
\n",
"
1
\n",
"
13
\n",
"
3436
\n",
"
2407404
\n",
"
1700000US1303436
\n",
"
1303436
\n",
"
Athens-Clarke County
\n",
"
Athens-Clarke County unified government
\n",
"
UG
\n",
"
308784927
\n",
"
4688313
\n",
"
POLYGON ((-83.53739 33.96591, -83.49824 33.987...
\n",
"
\n",
"
\n",
"
2
\n",
"
30
\n",
"
11390
\n",
"
2409651
\n",
"
1700000US3011390
\n",
"
3011390
\n",
"
Butte-Silver Bow
\n",
"
Butte-Silver Bow
\n",
"
00
\n",
"
1859568271
\n",
"
1518178
\n",
"
POLYGON ((-113.08552 45.86065, -113.08282 45.8...
\n",
"
\n",
"
\n",
"
3
\n",
"
21
\n",
"
48003
\n",
"
1967435
\n",
"
1700000US2148003
\n",
"
2148003
\n",
"
Louisville/Jefferson County
\n",
"
Louisville/Jefferson County metro government
\n",
"
MT
\n",
"
986271740
\n",
"
43513298
\n",
"
POLYGON ((-85.94711 38.00509, -85.94222 38.007...
\n",
"
\n",
"
\n",
"
4
\n",
"
09
\n",
"
47500
\n",
"
2378334
\n",
"
1700000US0947500
\n",
"
0947500
\n",
"
Milford
\n",
"
Milford city
\n",
"
25
\n",
"
57444044
\n",
"
10216676
\n",
"
POLYGON ((-73.12245 41.18290, -73.12137 41.187...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP CONCTYFP CONCTYNS AFFGEOID GEOID \\\n",
"0 20 28410 2664357 1700000US2028410 2028410 \n",
"1 13 3436 2407404 1700000US1303436 1303436 \n",
"2 30 11390 2409651 1700000US3011390 3011390 \n",
"3 21 48003 1967435 1700000US2148003 2148003 \n",
"4 09 47500 2378334 1700000US0947500 0947500 \n",
"\n",
" NAME NAMELSAD \\\n",
"0 Greeley County Greeley County unified government \n",
"1 Athens-Clarke County Athens-Clarke County unified government \n",
"2 Butte-Silver Bow Butte-Silver Bow \n",
"3 Louisville/Jefferson County Louisville/Jefferson County metro government \n",
"4 Milford Milford city \n",
"\n",
" LSAD ALAND AWATER \\\n",
"0 UG 2015424640 0 \n",
"1 UG 308784927 4688313 \n",
"2 00 1859568271 1518178 \n",
"3 MT 986271740 43513298 \n",
"4 25 57444044 10216676 \n",
"\n",
" geometry \n",
"0 POLYGON ((-102.04526 38.50540, -102.04526 38.5... \n",
"1 POLYGON ((-83.53739 33.96591, -83.49824 33.987... \n",
"2 POLYGON ((-113.08552 45.86065, -113.08282 45.8... \n",
"3 POLYGON ((-85.94711 38.00509, -85.94222 38.007... \n",
"4 POLYGON ((-73.12245 41.18290, -73.12137 41.187... "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_concity_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "e81eeeb3",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for Athens-Clarke County, GA, which is a Consolidated City. Select the data by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "5f1c64ab",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"Athens-Clarke County\"].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"Consolidated City: Athens-Clarke County, GA\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "92eb7d93",
"metadata": {},
"source": [
"The map created shows Athens-Clarke County, GA.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Counties (COUNTY)\n",
"\n",
"This file contains data on [Counties and Equivalent Entities](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_12). These are the primary legal divisions of states. Most states use the term \"counties,\" but other terms such as \"Parishes,\" \"Municipios,\" or \"Independent Cities\" may be used. \n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS Code\n",
"* COUNTYFP = County FIPS code\n",
"* COUNTNS = ANSI feature code for the county\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS and county FIPS code\n",
"* NAME = County name\n",
"* NAMELSAD = Name and Legal/statistical description\n",
"* STUSPS = FIPS State Postal Code\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for County polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Counties and Equivalent Entities data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "b814b4f8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
COUNTYNS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
21
\n",
"
141
\n",
"
00516917
\n",
"
0500000US21141
\n",
"
21141
\n",
"
Logan
\n",
"
Logan County
\n",
"
KY
\n",
"
Kentucky
\n",
"
06
\n",
"
1430224002
\n",
"
12479211
\n",
"
POLYGON ((-87.06037 36.68085, -87.06002 36.708...
\n",
"
\n",
"
\n",
"
1
\n",
"
36
\n",
"
081
\n",
"
00974139
\n",
"
0500000US36081
\n",
"
36081
\n",
"
Queens
\n",
"
Queens County
\n",
"
NY
\n",
"
New York
\n",
"
06
\n",
"
281594050
\n",
"
188444349
\n",
"
POLYGON ((-73.96262 40.73903, -73.96243 40.739...
\n",
"
\n",
"
\n",
"
2
\n",
"
34
\n",
"
017
\n",
"
00882278
\n",
"
0500000US34017
\n",
"
34017
\n",
"
Hudson
\n",
"
Hudson County
\n",
"
NJ
\n",
"
New Jersey
\n",
"
06
\n",
"
119640822
\n",
"
41836491
\n",
"
MULTIPOLYGON (((-74.04220 40.69997, -74.03900 ...
\n",
"
\n",
"
\n",
"
3
\n",
"
34
\n",
"
019
\n",
"
00882228
\n",
"
0500000US34019
\n",
"
34019
\n",
"
Hunterdon
\n",
"
Hunterdon County
\n",
"
NJ
\n",
"
New Jersey
\n",
"
06
\n",
"
1108086284
\n",
"
24761598
\n",
"
POLYGON ((-75.19511 40.57969, -75.19466 40.581...
\n",
"
\n",
"
\n",
"
4
\n",
"
21
\n",
"
147
\n",
"
00516926
\n",
"
0500000US21147
\n",
"
21147
\n",
"
McCreary
\n",
"
McCreary County
\n",
"
KY
\n",
"
Kentucky
\n",
"
06
\n",
"
1105416696
\n",
"
10730402
\n",
"
POLYGON ((-84.77845 36.60329, -84.73068 36.665...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP COUNTYFP COUNTYNS AFFGEOID GEOID NAME \\\n",
"0 21 141 00516917 0500000US21141 21141 Logan \n",
"1 36 081 00974139 0500000US36081 36081 Queens \n",
"2 34 017 00882278 0500000US34017 34017 Hudson \n",
"3 34 019 00882228 0500000US34019 34019 Hunterdon \n",
"4 21 147 00516926 0500000US21147 21147 McCreary \n",
"\n",
" NAMELSAD STUSPS STATE_NAME LSAD ALAND AWATER \\\n",
"0 Logan County KY Kentucky 06 1430224002 12479211 \n",
"1 Queens County NY New York 06 281594050 188444349 \n",
"2 Hudson County NJ New Jersey 06 119640822 41836491 \n",
"3 Hunterdon County NJ New Jersey 06 1108086284 24761598 \n",
"4 McCreary County KY Kentucky 06 1105416696 10730402 \n",
"\n",
" geometry \n",
"0 POLYGON ((-87.06037 36.68085, -87.06002 36.708... \n",
"1 POLYGON ((-73.96262 40.73903, -73.96243 40.739... \n",
"2 MULTIPOLYGON (((-74.04220 40.69997, -74.03900 ... \n",
"3 POLYGON ((-75.19511 40.57969, -75.19466 40.581... \n",
"4 POLYGON ((-84.77845 36.60329, -84.73068 36.665... "
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_county_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "2128eb88",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data for counties in Minnesota by filtering by the STATE_NAME column."
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "eb882430",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STATE_NAME == \"Minnesota\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Minnesota: Counties\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "447c0b7e",
"metadata": {},
"source": [
"The map created shows Minnesota Counties.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Counties within Congressional Districts: 116th Congress (COUNTY_within_CD116)\n",
"\n",
"This file contains data on Counties within Congressional Districts.\n",
"\n",
"The attribute PARTFLG identifies whether all or only part of a County is within a Congressional District:\n",
"\n",
"* N = All of a County is within a Congressional District\n",
"* Y = only part of a county is within a Congressional District\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* COUNTYFP = County FIPS code\n",
"* CD116FP = Congressional District FIPS code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS, Congressional District FIPS, and county FIPS code\n",
"* PARTFLD = Identifies if all or part of entity is within the file\n",
"* ALAND = Current Land Area\n",
"* geometry = coordinates for polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Counties within Congressional Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "316b1eb7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
CD116FP
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
PARTFLG
\n",
"
ALAND
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
05
\n",
"
057
\n",
"
4
\n",
"
5101600US0504057
\n",
"
0504057
\n",
"
N
\n",
"
1883438547
\n",
"
POLYGON ((-93.96945 33.74021, -93.96842 33.741...
\n",
"
\n",
"
\n",
"
1
\n",
"
54
\n",
"
037
\n",
"
2
\n",
"
5101600US5402037
\n",
"
5402037
\n",
"
N
\n",
"
542072983
\n",
"
POLYGON ((-78.03545 39.27822, -78.03326 39.279...
\n",
"
\n",
"
\n",
"
2
\n",
"
02
\n",
"
170
\n",
"
0
\n",
"
5101600US0200170
\n",
"
0200170
\n",
"
N
\n",
"
63990747114
\n",
"
POLYGON ((-153.00188 62.72583, -152.99961 62.7...
\n",
"
\n",
"
\n",
"
3
\n",
"
54
\n",
"
013
\n",
"
2
\n",
"
5101600US5402013
\n",
"
5402013
\n",
"
N
\n",
"
723253605
\n",
"
POLYGON ((-81.27841 38.91487, -81.27417 38.918...
\n",
"
\n",
"
\n",
"
4
\n",
"
12
\n",
"
077
\n",
"
2
\n",
"
5101600US1202077
\n",
"
1202077
\n",
"
N
\n",
"
2164099094
\n",
"
POLYGON ((-85.15381 30.09285, -85.15185 30.094...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP COUNTYFP CD116FP AFFGEOID GEOID PARTFLG ALAND \\\n",
"0 05 057 4 5101600US0504057 0504057 N 1883438547 \n",
"1 54 037 2 5101600US5402037 5402037 N 542072983 \n",
"2 02 170 0 5101600US0200170 0200170 N 63990747114 \n",
"3 54 013 2 5101600US5402013 5402013 N 723253605 \n",
"4 12 077 2 5101600US1202077 1202077 N 2164099094 \n",
"\n",
" geometry \n",
"0 POLYGON ((-93.96945 33.74021, -93.96842 33.741... \n",
"1 POLYGON ((-78.03545 39.27822, -78.03326 39.279... \n",
"2 POLYGON ((-153.00188 62.72583, -152.99961 62.7... \n",
"3 POLYGON ((-81.27841 38.91487, -81.27417 38.918... \n",
"4 POLYGON ((-85.15381 30.09285, -85.15185 30.094... "
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_county_within_cd116_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "22adb689",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only polygons where only part of the County is within a Congressional District. Select the relevant data by filtering by `\"Y\"` in the PARTFLG column."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "e60138d7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.PARTFLG == \"Y\"].plot(figsize=(20, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Counties only partially within a Congressional Districts\",\n",
" fontdict={\"fontsize\": \"30\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "36fac814",
"metadata": {},
"source": [
"The map created shows Counties partially within Congressional Districts.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### County Subdivisions (COUSUB)\n",
"\n",
"This file contains [County Subdivisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_11), which are the primary divisions of counties and equivalent entities. These divisions vary from state to state and include Barrios, Purchases, Townships, and other types of legal and statistical entities. \n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* COUNTYFP = County FIPS code\n",
"* COUSUBFP = Subdivision FIPS code\n",
"* COUSUBNS = ANSI feature for the subdivision\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS, county FIPS, and county subdivision FIPS\n",
"* NAME = Subdivision name\n",
"* NAMELSAD = Subdivision name and legal/statistical description\n",
"* STUSPS = FIPS State Postal Code\n",
"* NAMELSADCO = County name\n",
"* STATE_NAME = State Name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for County Subdivision polygons\n",
"\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the County Subdivisions data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "2178f2d4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
COUSUBFP
\n",
"
COUSUBNS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
STUSPS
\n",
"
NAMELSADCO
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
42
\n",
"
117
\n",
"
52960
\n",
"
01217118
\n",
"
0600000US4211752960
\n",
"
4211752960
\n",
"
Nelson
\n",
"
Nelson township
\n",
"
PA
\n",
"
Tioga County
\n",
"
Pennsylvania
\n",
"
44
\n",
"
29020811
\n",
"
25916
\n",
"
POLYGON ((-77.31788 41.97075, -77.31029 41.970...
\n",
"
\n",
"
\n",
"
1
\n",
"
46
\n",
"
109
\n",
"
42820
\n",
"
01268550
\n",
"
0600000US4610942820
\n",
"
4610942820
\n",
"
Minnesota
\n",
"
Minnesota township
\n",
"
SD
\n",
"
Roberts County
\n",
"
South Dakota
\n",
"
44
\n",
"
121465694
\n",
"
3383863
\n",
"
POLYGON ((-97.10387 45.90342, -97.10309 45.908...
\n",
"
\n",
"
\n",
"
2
\n",
"
46
\n",
"
083
\n",
"
20780
\n",
"
01267387
\n",
"
0600000US4608320780
\n",
"
4608320780
\n",
"
Fairview
\n",
"
Fairview town
\n",
"
SD
\n",
"
Lincoln County
\n",
"
South Dakota
\n",
"
43
\n",
"
221380
\n",
"
0
\n",
"
POLYGON ((-96.49153 43.22389, -96.48526 43.224...
\n",
"
\n",
"
\n",
"
3
\n",
"
47
\n",
"
009
\n",
"
91340
\n",
"
02464659
\n",
"
0600000US4700991340
\n",
"
4700991340
\n",
"
8
\n",
"
District 8
\n",
"
TN
\n",
"
Blount County
\n",
"
Tennessee
\n",
"
28
\n",
"
646087619
\n",
"
509512
\n",
"
POLYGON ((-83.99881 35.55556, -83.99444 35.558...
\n",
"
\n",
"
\n",
"
4
\n",
"
48
\n",
"
489
\n",
"
93435
\n",
"
01939169
\n",
"
0600000US4848993435
\n",
"
4848993435
\n",
"
San Perlita
\n",
"
San Perlita CCD
\n",
"
TX
\n",
"
Willacy County
\n",
"
Texas
\n",
"
22
\n",
"
739156645
\n",
"
483409952
\n",
"
MULTIPOLYGON (((-97.25810 26.42544, -97.25596 ...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP COUNTYFP COUSUBFP COUSUBNS AFFGEOID GEOID \\\n",
"0 42 117 52960 01217118 0600000US4211752960 4211752960 \n",
"1 46 109 42820 01268550 0600000US4610942820 4610942820 \n",
"2 46 083 20780 01267387 0600000US4608320780 4608320780 \n",
"3 47 009 91340 02464659 0600000US4700991340 4700991340 \n",
"4 48 489 93435 01939169 0600000US4848993435 4848993435 \n",
"\n",
" NAME NAMELSAD STUSPS NAMELSADCO STATE_NAME LSAD \\\n",
"0 Nelson Nelson township PA Tioga County Pennsylvania 44 \n",
"1 Minnesota Minnesota township SD Roberts County South Dakota 44 \n",
"2 Fairview Fairview town SD Lincoln County South Dakota 43 \n",
"3 8 District 8 TN Blount County Tennessee 28 \n",
"4 San Perlita San Perlita CCD TX Willacy County Texas 22 \n",
"\n",
" ALAND AWATER geometry \n",
"0 29020811 25916 POLYGON ((-77.31788 41.97075, -77.31029 41.970... \n",
"1 121465694 3383863 POLYGON ((-97.10387 45.90342, -97.10309 45.908... \n",
"2 221380 0 POLYGON ((-96.49153 43.22389, -96.48526 43.224... \n",
"3 646087619 509512 POLYGON ((-83.99881 35.55556, -83.99444 35.558... \n",
"4 739156645 483409952 MULTIPOLYGON (((-97.25810 26.42544, -97.25596 ... "
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_cousub_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "ad6bd347",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, plot all the subdivisions, townships in this case, in Bergen County, NJ. Select the relevant data by filtering by the NAMELSADCO column."
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "7f2b68e2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAMELSADCO == \"Bergen County\"].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"County Subdivisions: Bergen County, NJ\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "51f43698",
"metadata": {},
"source": [
"The map created shows County Subdivisions in Bergen County, NJ.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Divisions (DIVISION)\n",
"\n",
"This file contains data on [Divisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_10) of the US. This file is similar to the Regions file but contains more divisions and encompasses several states per division.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* DIVISIONCE = Number assigned to each division\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = DIVISIONCE\n",
"* NAME = Name of division\n",
"* NAMELSAD = Division name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Division polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Division data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "14f15693",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
DIVISIONCE
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
5
\n",
"
0300000US5
\n",
"
5
\n",
"
South Atlantic
\n",
"
South Atlantic Division
\n",
"
69
\n",
"
687125298338
\n",
"
86339601557
\n",
"
MULTIPOLYGON (((-75.56555 39.51485, -75.56174 ...
\n",
"
\n",
"
\n",
"
1
\n",
"
3
\n",
"
0300000US3
\n",
"
3
\n",
"
East North Central
\n",
"
East North Central Division
\n",
"
69
\n",
"
629298010339
\n",
"
151248789139
\n",
"
MULTIPOLYGON (((-82.73447 41.60351, -82.72425 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
4
\n",
"
0300000US4
\n",
"
4
\n",
"
West North Central
\n",
"
West North Central Division
\n",
"
69
\n",
"
1314700010733
\n",
"
33034200327
\n",
"
MULTIPOLYGON (((-89.59206 47.96668, -89.59147 ...
\n",
"
\n",
"
\n",
"
3
\n",
"
8
\n",
"
0300000US8
\n",
"
8
\n",
"
Mountain
\n",
"
Mountain Division
\n",
"
69
\n",
"
2217352931824
\n",
"
19266522413
\n",
"
POLYGON ((-120.00574 39.22866, -120.00567 39.2...
\n",
"
\n",
"
\n",
"
4
\n",
"
9
\n",
"
0300000US9
\n",
"
9
\n",
"
Pacific
\n",
"
Pacific Division
\n",
"
69
\n",
"
2319992840165
\n",
"
296172644163
\n",
"
MULTIPOLYGON (((-139.51201 59.70289, -139.5095...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" DIVISIONCE AFFGEOID GEOID NAME \\\n",
"0 5 0300000US5 5 South Atlantic \n",
"1 3 0300000US3 3 East North Central \n",
"2 4 0300000US4 4 West North Central \n",
"3 8 0300000US8 8 Mountain \n",
"4 9 0300000US9 9 Pacific \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 South Atlantic Division 69 687125298338 86339601557 \n",
"1 East North Central Division 69 629298010339 151248789139 \n",
"2 West North Central Division 69 1314700010733 33034200327 \n",
"3 Mountain Division 69 2217352931824 19266522413 \n",
"4 Pacific Division 69 2319992840165 296172644163 \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((-75.56555 39.51485, -75.56174 ... \n",
"1 MULTIPOLYGON (((-82.73447 41.60351, -82.72425 ... \n",
"2 MULTIPOLYGON (((-89.59206 47.96668, -89.59147 ... \n",
"3 POLYGON ((-120.00574 39.22866, -120.00567 39.2... \n",
"4 MULTIPOLYGON (((-139.51201 59.70289, -139.5095... "
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_division_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "f37be166",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select only data from the Mountain division by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "9aa415a3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"Mountain\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Divisions: Mountain Region\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "e1286f9e",
"metadata": {},
"source": [
"The map created shows the Mountain Region Division.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Metropolitan and Micropolitan Statistical Areas and Related Statistical Areas\n",
"\n",
"[Metropolitan and Micropolitan Statistical Areas and Related Statistical Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7) is the second grouping of datasets within the census data by cartographic boundaries group. A metropolitan or micropolitan statistical area contains a core area, with a substantial population with adjacent communities having a high degree of economic and social integration with that core. This grouping contains six datasets.\n",
"\n",
"#### Core Based Statistical Areas (CBSAs)\n",
"\n",
"This file contains data on [Core Based Statistical Areas (CBSAs)](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7). This encompasses all metropolitan and micropolitan statistical areas.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* CSAFP = Combined statistical area code (if applicable)\n",
"* CBSAFP = Metropolitan statistical area/micropolitan statistical area code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = CBSAFP\n",
"* NAME = Metropolitan statistical area/micropolitan statistical area name\n",
"* NAMELSAD = CBSA name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for CBSA polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the CBSA data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "83a2273d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
CSAFP
\n",
"
CBSAFP
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
<NA>
\n",
"
11380
\n",
"
310M600US11380
\n",
"
11380
\n",
"
Andrews, TX
\n",
"
Andrews, TX Micro Area
\n",
"
M2
\n",
"
3886850259
\n",
"
957039
\n",
"
POLYGON ((-103.06470 32.52219, -103.00047 32.5...
\n",
"
\n",
"
\n",
"
1
\n",
"
192
\n",
"
35140
\n",
"
310M600US35140
\n",
"
35140
\n",
"
Newberry, SC
\n",
"
Newberry, SC Micro Area
\n",
"
M2
\n",
"
1632452022
\n",
"
44011454
\n",
"
POLYGON ((-81.94372 34.20605, -81.94196 34.208...
\n",
"
\n",
"
\n",
"
2
\n",
"
<NA>
\n",
"
37540
\n",
"
310M600US37540
\n",
"
37540
\n",
"
Paris, TN
\n",
"
Paris, TN Micro Area
\n",
"
M2
\n",
"
1455320362
\n",
"
81582236
\n",
"
POLYGON ((-88.52940 36.17018, -88.52636 36.229...
\n",
"
\n",
"
\n",
"
3
\n",
"
246
\n",
"
29900
\n",
"
310M600US29900
\n",
"
29900
\n",
"
Laurinburg, NC
\n",
"
Laurinburg, NC Micro Area
\n",
"
M2
\n",
"
826569986
\n",
"
3842049
\n",
"
POLYGON ((-79.69251 34.80685, -79.68822 34.809...
\n",
"
\n",
"
\n",
"
4
\n",
"
315
\n",
"
35460
\n",
"
310M600US35460
\n",
"
35460
\n",
"
Newport, TN
\n",
"
Newport, TN Micro Area
\n",
"
M2
\n",
"
1129584563
\n",
"
17932684
\n",
"
POLYGON ((-83.31519 35.89332, -83.31078 35.895...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" CSAFP CBSAFP AFFGEOID GEOID NAME \\\n",
"0 11380 310M600US11380 11380 Andrews, TX \n",
"1 192 35140 310M600US35140 35140 Newberry, SC \n",
"2 37540 310M600US37540 37540 Paris, TN \n",
"3 246 29900 310M600US29900 29900 Laurinburg, NC \n",
"4 315 35460 310M600US35460 35460 Newport, TN \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 Andrews, TX Micro Area M2 3886850259 957039 \n",
"1 Newberry, SC Micro Area M2 1632452022 44011454 \n",
"2 Paris, TN Micro Area M2 1455320362 81582236 \n",
"3 Laurinburg, NC Micro Area M2 826569986 3842049 \n",
"4 Newport, TN Micro Area M2 1129584563 17932684 \n",
"\n",
" geometry \n",
"0 POLYGON ((-103.06470 32.52219, -103.00047 32.5... \n",
"1 POLYGON ((-81.94372 34.20605, -81.94196 34.208... \n",
"2 POLYGON ((-88.52940 36.17018, -88.52636 36.229... \n",
"3 POLYGON ((-79.69251 34.80685, -79.68822 34.809... \n",
"4 POLYGON ((-83.31519 35.89332, -83.31078 35.895... "
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_cbsa_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "1ef58096",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select Kahului-Wailuku-Lahaina, HI Metro Area by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "447b031a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"Kahului-Wailuku-Lahaina, HI\"].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"Core Based Statistical Area: Kahului-Wailuku-Lahaina, HI Metro Area\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "2fb24449",
"metadata": {},
"source": [
"The map created shows the Kahului-Wailuku-Lahaina, HI Metro Area, Core Based Statistical Area.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### Combined Statistical Areas (CSA)\n",
"\n",
"This file contains data on [Combined Statistical Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), which are areas that consist of two or more adjacent CBSAs that have significant employment interchanges.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* CSAFP = Combined statistical area code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = CSAFP\n",
"* NAME = CSA Name\n",
"* NAMELSAD = CSA name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for CSA polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the CSA data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "ce322267",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
CSAFP
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
146
\n",
"
330M600US146
\n",
"
146
\n",
"
Bloomsburg-Berwick-Sunbury, PA
\n",
"
Bloomsburg-Berwick-Sunbury, PA CSA
\n",
"
M0
\n",
"
4444039108
\n",
"
86464626
\n",
"
POLYGON ((-77.36418 40.84694, -77.27924 40.909...
\n",
"
\n",
"
\n",
"
1
\n",
"
368
\n",
"
330M600US368
\n",
"
368
\n",
"
Memphis-Forrest City, TN-MS-AR
\n",
"
Memphis-Forrest City, TN-MS-AR CSA
\n",
"
M0
\n",
"
13493874541
\n",
"
322004792
\n",
"
POLYGON ((-91.15230 34.92548, -91.15074 34.968...
\n",
"
\n",
"
\n",
"
2
\n",
"
356
\n",
"
330M600US356
\n",
"
356
\n",
"
Macon-Bibb County--Warner Robins, GA
\n",
"
Macon-Bibb County--Warner Robins, GA CSA
\n",
"
M0
\n",
"
5827265752
\n",
"
49165153
\n",
"
POLYGON ((-84.20263 32.69002, -84.19676 32.701...
\n",
"
\n",
"
\n",
"
3
\n",
"
290
\n",
"
330M600US290
\n",
"
290
\n",
"
Huntsville-Decatur, AL
\n",
"
Huntsville-Decatur, AL CSA
\n",
"
M0
\n",
"
6816635309
\n",
"
269975554
\n",
"
POLYGON ((-87.53028 34.45756, -87.53011 34.469...
\n",
"
\n",
"
\n",
"
4
\n",
"
206
\n",
"
330M600US206
\n",
"
206
\n",
"
Dallas-Fort Worth, TX-OK
\n",
"
Dallas-Fort Worth, TX-OK CSA
\n",
"
M0
\n",
"
40234482778
\n",
"
1682397922
\n",
"
POLYGON ((-98.57613 32.57248, -98.57600 32.624...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" CSAFP AFFGEOID GEOID NAME \\\n",
"0 146 330M600US146 146 Bloomsburg-Berwick-Sunbury, PA \n",
"1 368 330M600US368 368 Memphis-Forrest City, TN-MS-AR \n",
"2 356 330M600US356 356 Macon-Bibb County--Warner Robins, GA \n",
"3 290 330M600US290 290 Huntsville-Decatur, AL \n",
"4 206 330M600US206 206 Dallas-Fort Worth, TX-OK \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 Bloomsburg-Berwick-Sunbury, PA CSA M0 4444039108 86464626 \n",
"1 Memphis-Forrest City, TN-MS-AR CSA M0 13493874541 322004792 \n",
"2 Macon-Bibb County--Warner Robins, GA CSA M0 5827265752 49165153 \n",
"3 Huntsville-Decatur, AL CSA M0 6816635309 269975554 \n",
"4 Dallas-Fort Worth, TX-OK CSA M0 40234482778 1682397922 \n",
"\n",
" geometry \n",
"0 POLYGON ((-77.36418 40.84694, -77.27924 40.909... \n",
"1 POLYGON ((-91.15230 34.92548, -91.15074 34.968... \n",
"2 POLYGON ((-84.20263 32.69002, -84.19676 32.701... \n",
"3 POLYGON ((-87.53028 34.45756, -87.53011 34.469... \n",
"4 POLYGON ((-98.57613 32.57248, -98.57600 32.624... "
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_csa_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "df2dff21",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select the San Jose-San Francisco-Oakland CSA by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "ea4f7d12",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"San Jose-San Francisco-Oakland, CA\"].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"Combined Statistical Area: San Jose-San Francisco-Oakland, CA\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "9f52d0a7",
"metadata": {},
"source": [
"The map created shows the San Jose-San Francisco-Oakland, CA Combined Statistical Area.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### Metropolitan Divisions (METDIV)\n",
"\n",
"This file contains data on [Metropolitan Divisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7). These areas are groupings of counties or equivalent entities within a metropolitan statistical area with a core of 2.5 million inhabitants and one or more main counties that represent employment centers, plus adjacent counties with commuting ties.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* CSAFP = Combined statistical area code\n",
"* CBSAFP = Metropolitan statistical area/micropolitan statistical area code\n",
"* METDIVFP = Metropolitan division code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of CBSAFP and METDIVFP\n",
"* NAME = Metropolitan division name\n",
"* NAMELSAD = MetDiv name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Metropolitan Division polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Metropolitan Division data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "3968d531",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
CSAFP
\n",
"
CBSAFP
\n",
"
METDIVFP
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
348
\n",
"
31080
\n",
"
11244
\n",
"
314M600US3108011244
\n",
"
3108011244
\n",
"
Anaheim-Santa Ana-Irvine, CA
\n",
"
Anaheim-Santa Ana-Irvine, CA Metro Division
\n",
"
M3
\n",
"
2053449483
\n",
"
406294114
\n",
"
POLYGON ((-118.11442 33.74518, -118.11305 33.7...
\n",
"
\n",
"
\n",
"
1
\n",
"
148
\n",
"
14460
\n",
"
14454
\n",
"
314M600US1446014454
\n",
"
1446014454
\n",
"
Boston, MA
\n",
"
Boston, MA Metro Division
\n",
"
M3
\n",
"
2882301581
\n",
"
1411559356
\n",
"
MULTIPOLYGON (((-70.88335 42.34049, -70.88158 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
148
\n",
"
14460
\n",
"
15764
\n",
"
314M600US1446015764
\n",
"
1446015764
\n",
"
Cambridge-Newton-Framingham, MA
\n",
"
Cambridge-Newton-Framingham, MA Metro Division
\n",
"
M3
\n",
"
3393859579
\n",
"
945476893
\n",
"
MULTIPOLYGON (((-70.58029 42.63602, -70.57509 ...
\n",
"
\n",
"
\n",
"
3
\n",
"
428
\n",
"
37980
\n",
"
15804
\n",
"
314M600US3798015804
\n",
"
3798015804
\n",
"
Camden, NJ
\n",
"
Camden, NJ Metro Division
\n",
"
M3
\n",
"
3477449505
\n",
"
108072755
\n",
"
POLYGON ((-75.42830 39.78437, -75.42168 39.787...
\n",
"
\n",
"
\n",
"
4
\n",
"
176
\n",
"
16980
\n",
"
16984
\n",
"
314M600US1698016984
\n",
"
1698016984
\n",
"
Chicago-Naperville-Evanston, IL
\n",
"
Chicago-Naperville-Evanston, IL Metro Division
\n",
"
M3
\n",
"
8106981077
\n",
"
1895152877
\n",
"
POLYGON ((-88.70738 42.49359, -88.67080 42.494...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" CSAFP CBSAFP METDIVFP AFFGEOID GEOID \\\n",
"0 348 31080 11244 314M600US3108011244 3108011244 \n",
"1 148 14460 14454 314M600US1446014454 1446014454 \n",
"2 148 14460 15764 314M600US1446015764 1446015764 \n",
"3 428 37980 15804 314M600US3798015804 3798015804 \n",
"4 176 16980 16984 314M600US1698016984 1698016984 \n",
"\n",
" NAME \\\n",
"0 Anaheim-Santa Ana-Irvine, CA \n",
"1 Boston, MA \n",
"2 Cambridge-Newton-Framingham, MA \n",
"3 Camden, NJ \n",
"4 Chicago-Naperville-Evanston, IL \n",
"\n",
" NAMELSAD LSAD ALAND \\\n",
"0 Anaheim-Santa Ana-Irvine, CA Metro Division M3 2053449483 \n",
"1 Boston, MA Metro Division M3 2882301581 \n",
"2 Cambridge-Newton-Framingham, MA Metro Division M3 3393859579 \n",
"3 Camden, NJ Metro Division M3 3477449505 \n",
"4 Chicago-Naperville-Evanston, IL Metro Division M3 8106981077 \n",
"\n",
" AWATER geometry \n",
"0 406294114 POLYGON ((-118.11442 33.74518, -118.11305 33.7... \n",
"1 1411559356 MULTIPOLYGON (((-70.88335 42.34049, -70.88158 ... \n",
"2 945476893 MULTIPOLYGON (((-70.58029 42.63602, -70.57509 ... \n",
"3 108072755 POLYGON ((-75.42830 39.78437, -75.42168 39.787... \n",
"4 1895152877 POLYGON ((-88.70738 42.49359, -88.67080 42.494... "
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_metdiv_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "3d380b0b",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select out Chicago-Naperville-Evanston, IL Metropolitan Divisions by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "6889344d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"Chicago-Naperville-Evanston, IL\"].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"Metropolitan Divisions: Chicago-Naperville-Evanston, IL\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "cc7972e9",
"metadata": {},
"source": [
"The map created shows Metropolitan Divisions in Illinois and Indiana.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### New England City and Town Areas (NECTA)\n",
"\n",
"This file contains [New England City and Town Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), which encompass metropolitan and micropolitan statistical areas and urban clusters in New England.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* CNECTAFP = Combined NECTA code\n",
"* NECTAFP = NECTA code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = NECTAFP\n",
"* NAME = NECTA name\n",
"* NAMELSAD = NECTA name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for New England City and Town Area polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the New England City and Town Areas data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "0345e2c4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
CNECTAFP
\n",
"
NECTAFP
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
790
\n",
"
73300
\n",
"
350M600US73300
\n",
"
73300
\n",
"
Greenfield Town, MA
\n",
"
Greenfield Town, MA Micropolitan NECTA
\n",
"
M6
\n",
"
576790797
\n",
"
12695651
\n",
"
POLYGON ((-72.85766 42.73761, -72.80911 42.736...
\n",
"
\n",
"
\n",
"
1
\n",
"
725
\n",
"
72500
\n",
"
350M600US72500
\n",
"
72500
\n",
"
Claremont, NH
\n",
"
Claremont, NH Micropolitan NECTA
\n",
"
M6
\n",
"
207547766
\n",
"
2886013
\n",
"
POLYGON ((-72.41538 43.38021, -72.41315 43.384...
\n",
"
\n",
"
\n",
"
2
\n",
"
NaN
\n",
"
73050
\n",
"
350M600US73050
\n",
"
73050
\n",
"
Dover-Durham, NH-ME
\n",
"
Dover-Durham, NH-ME Metropolitan NECTA
\n",
"
M5
\n",
"
1153772202
\n",
"
38371631
\n",
"
POLYGON ((-71.24697 43.27619, -71.23601 43.284...
\n",
"
\n",
"
\n",
"
3
\n",
"
NaN
\n",
"
78500
\n",
"
350M600US78500
\n",
"
78500
\n",
"
Vineyard Haven, MA
\n",
"
Vineyard Haven, MA Micropolitan NECTA
\n",
"
M6
\n",
"
233141285
\n",
"
675399599
\n",
"
MULTIPOLYGON (((-70.83204 41.25950, -70.82983 ...
\n",
"
\n",
"
\n",
"
4
\n",
"
715
\n",
"
74500
\n",
"
350M600US74500
\n",
"
74500
\n",
"
Leominster-Gardner, MA
\n",
"
Leominster-Gardner, MA Metropolitan NECTA
\n",
"
M5
\n",
"
1028154238
\n",
"
65184023
\n",
"
POLYGON ((-72.31363 42.39640, -72.31509 42.398...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" CNECTAFP NECTAFP AFFGEOID GEOID NAME \\\n",
"0 790 73300 350M600US73300 73300 Greenfield Town, MA \n",
"1 725 72500 350M600US72500 72500 Claremont, NH \n",
"2 NaN 73050 350M600US73050 73050 Dover-Durham, NH-ME \n",
"3 NaN 78500 350M600US78500 78500 Vineyard Haven, MA \n",
"4 715 74500 350M600US74500 74500 Leominster-Gardner, MA \n",
"\n",
" NAMELSAD LSAD ALAND AWATER \\\n",
"0 Greenfield Town, MA Micropolitan NECTA M6 576790797 12695651 \n",
"1 Claremont, NH Micropolitan NECTA M6 207547766 2886013 \n",
"2 Dover-Durham, NH-ME Metropolitan NECTA M5 1153772202 38371631 \n",
"3 Vineyard Haven, MA Micropolitan NECTA M6 233141285 675399599 \n",
"4 Leominster-Gardner, MA Metropolitan NECTA M5 1028154238 65184023 \n",
"\n",
" geometry \n",
"0 POLYGON ((-72.85766 42.73761, -72.80911 42.736... \n",
"1 POLYGON ((-72.41538 43.38021, -72.41315 43.384... \n",
"2 POLYGON ((-71.24697 43.27619, -71.23601 43.284... \n",
"3 MULTIPOLYGON (((-70.83204 41.25950, -70.82983 ... \n",
"4 POLYGON ((-72.31363 42.39640, -72.31509 42.398... "
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_necta_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "cdbdf054",
"metadata": {},
"source": [
"Next, plot all polygons from this parquet file and overlay all of the New England City and Town Areas on a basemap."
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "10c21538",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf.plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"New England City and Town Areas\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "bbd50bb4",
"metadata": {},
"source": [
"The map created shows New England City and Town Areas.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### New England City and Town Area Division (NECTADIV)\n",
"\n",
"This file contains [New England City and Town Areas Divisions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), which are smaller groupings of cities and towns in New England that contain a single core of 2.5 million inhabitants. Each division must have a total population of 100,000 or more.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* CNECTAFP = Combined NECTA code\n",
"* NECTAFP = NECTA code\n",
"* NCTADVFP = NECTA Division code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of NECTA code and NECT division code\n",
"* NAME = NECTA Division name\n",
"* NAMELSAD = NECTA Division name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for New England City and Town Area Division polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the New England City and Town Areas Divisions data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "acbfb7d1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf.plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"New England City and Town Area Divisions\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "251efae3",
"metadata": {},
"source": [
"The map created shows New England City and Town Area Divisions.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### Combined New England City and Town Areas (CNECTA)\n",
"\n",
"This file contains data on [Combined New England City and Town Areas](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_7), consisting of two or more adjacent NECTAs that have significant employment interchanges.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* CNECTAFP = Combined NECTA code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = CNECTA\n",
"* NAME = Combined NECTA name\n",
"* NAMELSAD = Combined NECTA name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Combined New England City and Town Area polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Combined New England City and Town Areas data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "2c39b796",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf.plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Combined New England City and Town Areas\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "87a35a52",
"metadata": {},
"source": [
"The map created shows Combined New England City and Town Areas.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Places (PLACE)\n",
"\n",
"This file contains [Places](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_14) which are Incorporated Places (legal entities) and Census Designated Places (CDPs, statistical entities). An incorporated place usually is a city, town, village, or borough but can have other legal descriptions. CDPs are settled concentrations of population that are identifiable by name but are not legally incorporated.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* PLACEFP = Place FIPS code\n",
"* PLACENS = Place GNIS code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code and Place FIPS code\n",
"* NAME = Place name\n",
"* NAMELSAD = Place name and legal/statistical description\n",
"* STUSPS = FIPS Postal code\n",
"* STATE_NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Place polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Places data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "e2e16cda",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
PLACEFP
\n",
"
PLACENS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
12
\n",
"
28575
\n",
"
2403791
\n",
"
1600000US1228575
\n",
"
1228575
\n",
"
Hampton
\n",
"
Hampton city
\n",
"
FL
\n",
"
Florida
\n",
"
25
\n",
"
2728657
\n",
"
0
\n",
"
POLYGON ((-82.15433 29.86419, -82.14682 29.864...
\n",
"
\n",
"
\n",
"
1
\n",
"
12
\n",
"
625
\n",
"
2405131
\n",
"
1600000US1200625
\n",
"
1200625
\n",
"
Alford
\n",
"
Alford town
\n",
"
FL
\n",
"
Florida
\n",
"
43
\n",
"
2731534
\n",
"
49685
\n",
"
POLYGON ((-85.40333 30.70450, -85.39543 30.704...
\n",
"
\n",
"
\n",
"
2
\n",
"
12
\n",
"
26050
\n",
"
2406576
\n",
"
1600000US1226050
\n",
"
1226050
\n",
"
Glen Ridge
\n",
"
Glen Ridge town
\n",
"
FL
\n",
"
Florida
\n",
"
43
\n",
"
442668
\n",
"
54824
\n",
"
POLYGON ((-80.08267 26.67634, -80.07902 26.676...
\n",
"
\n",
"
\n",
"
3
\n",
"
13
\n",
"
69000
\n",
"
2405429
\n",
"
1600000US1369000
\n",
"
1369000
\n",
"
Savannah
\n",
"
Savannah city
\n",
"
GA
\n",
"
Georgia
\n",
"
25
\n",
"
276730651
\n",
"
12329738
\n",
"
MULTIPOLYGON (((-81.23851 32.06725, -81.21279 ...
\n",
"
\n",
"
\n",
"
4
\n",
"
13
\n",
"
67284
\n",
"
2404651
\n",
"
1600000US1367284
\n",
"
1367284
\n",
"
Roswell
\n",
"
Roswell city
\n",
"
GA
\n",
"
Georgia
\n",
"
25
\n",
"
105461127
\n",
"
3308483
\n",
"
POLYGON ((-84.41903 34.06118, -84.41903 34.061...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP PLACEFP PLACENS AFFGEOID GEOID NAME \\\n",
"0 12 28575 2403791 1600000US1228575 1228575 Hampton \n",
"1 12 625 2405131 1600000US1200625 1200625 Alford \n",
"2 12 26050 2406576 1600000US1226050 1226050 Glen Ridge \n",
"3 13 69000 2405429 1600000US1369000 1369000 Savannah \n",
"4 13 67284 2404651 1600000US1367284 1367284 Roswell \n",
"\n",
" NAMELSAD STUSPS STATE_NAME LSAD ALAND AWATER \\\n",
"0 Hampton city FL Florida 25 2728657 0 \n",
"1 Alford town FL Florida 43 2731534 49685 \n",
"2 Glen Ridge town FL Florida 43 442668 54824 \n",
"3 Savannah city GA Georgia 25 276730651 12329738 \n",
"4 Roswell city GA Georgia 25 105461127 3308483 \n",
"\n",
" geometry \n",
"0 POLYGON ((-82.15433 29.86419, -82.14682 29.864... \n",
"1 POLYGON ((-85.40333 30.70450, -85.39543 30.704... \n",
"2 POLYGON ((-80.08267 26.67634, -80.07902 26.676... \n",
"3 MULTIPOLYGON (((-81.23851 32.06725, -81.21279 ... \n",
"4 POLYGON ((-84.41903 34.06118, -84.41903 34.061... "
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_place_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "6ba97d70",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select all the Places in Washington State by filtering by `\"WA\"` in the STUSPS column."
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "0204a153",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STUSPS == \"WA\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Places: Washington State\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "0a124d69",
"metadata": {},
"source": [
"The map created shows Places in Washington State.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Regions (REGION)\n",
"\n",
"This file contains [Regions](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_10) of the US and encompasses several states per division.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* REGIONCE = Number assigned to each Region\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = REGIONCE\n",
"* NAME = Name of region\n",
"* NAMELSAD = Region name and legal/statistical description\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Region polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Regions data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "7bccb527",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
REGIONCE
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
3
\n",
"
0200000US3
\n",
"
3
\n",
"
South
\n",
"
South Region
\n",
"
68
\n",
"
2249827294436
\n",
"
148750821211
\n",
"
MULTIPOLYGON (((-89.34216 30.05917, -89.33606 ...
\n",
"
\n",
"
\n",
"
1
\n",
"
2
\n",
"
0200000US2
\n",
"
2
\n",
"
Midwest
\n",
"
Midwest Region
\n",
"
68
\n",
"
1943998021072
\n",
"
184282989466
\n",
"
MULTIPOLYGON (((-82.73447 41.60351, -82.72425 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
4
\n",
"
0200000US4
\n",
"
4
\n",
"
West
\n",
"
West Region
\n",
"
68
\n",
"
4537345771989
\n",
"
315439166576
\n",
"
MULTIPOLYGON (((-147.46941 60.92206, -147.4682...
\n",
"
\n",
"
\n",
"
3
\n",
"
1
\n",
"
0200000US1
\n",
"
1
\n",
"
Northeast
\n",
"
Northeast Region
\n",
"
68
\n",
"
419355661549
\n",
"
50259697277
\n",
"
MULTIPOLYGON (((-67.32260 44.61160, -67.32174 ...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" REGIONCE AFFGEOID GEOID NAME NAMELSAD LSAD \\\n",
"0 3 0200000US3 3 South South Region 68 \n",
"1 2 0200000US2 2 Midwest Midwest Region 68 \n",
"2 4 0200000US4 4 West West Region 68 \n",
"3 1 0200000US1 1 Northeast Northeast Region 68 \n",
"\n",
" ALAND AWATER \\\n",
"0 2249827294436 148750821211 \n",
"1 1943998021072 184282989466 \n",
"2 4537345771989 315439166576 \n",
"3 419355661549 50259697277 \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((-89.34216 30.05917, -89.33606 ... \n",
"1 MULTIPOLYGON (((-82.73447 41.60351, -82.72425 ... \n",
"2 MULTIPOLYGON (((-147.46941 60.92206, -147.4682... \n",
"3 MULTIPOLYGON (((-67.32260 44.61160, -67.32174 ... "
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_region_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "238c9abb",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select the entire South Region by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "8f57198c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"South\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"South Region\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "1955567e",
"metadata": {},
"source": [
"The map created shows the South Region.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### School Districts \n",
"\n",
"[School Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_23) is the third grouping of datasets within the census data by cartographic boundaries group. This dataset grouping includes district boundaries for Elementary School Districts, Secondary School Districts, and Unified School Districts.\n",
"\n",
"#### School Districts - Elementary (ELSD)\n",
"\n",
"This file contains [Elementary School Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_23), referring to districts with elementary schools.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* ELSDLEA = Elementary School District local education agency code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code and ELSDLEA code\n",
"* NAME = Elementary School District name\n",
"* STUSPS = FIPS Postal code\n",
"* STATE_NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Elementary School District polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Elementary School Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "cf3e3cc4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
ELSDLEA
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
17
\n",
"
42570
\n",
"
9500000US1742570
\n",
"
1742570
\n",
"
Willow Springs School District 108
\n",
"
IL
\n",
"
Illinois
\n",
"
00
\n",
"
24565916
\n",
"
2685308
\n",
"
POLYGON ((-87.91426 41.71660, -87.90923 41.719...
\n",
"
\n",
"
\n",
"
1
\n",
"
40
\n",
"
4470
\n",
"
9500000US4004470
\n",
"
4004470
\n",
"
Bishop Public School
\n",
"
OK
\n",
"
Oklahoma
\n",
"
00
\n",
"
18936631
\n",
"
0
\n",
"
POLYGON ((-98.44840 34.59449, -98.43973 34.594...
\n",
"
\n",
"
\n",
"
2
\n",
"
17
\n",
"
8790
\n",
"
9500000US1708790
\n",
"
1708790
\n",
"
Cass School District 63
\n",
"
IL
\n",
"
Illinois
\n",
"
00
\n",
"
11006857
\n",
"
329296
\n",
"
POLYGON ((-88.00218 41.72823, -88.00230 41.729...
\n",
"
\n",
"
\n",
"
3
\n",
"
34
\n",
"
5520
\n",
"
9500000US3405520
\n",
"
3405520
\n",
"
Franklin Township School District
\n",
"
NJ
\n",
"
New Jersey
\n",
"
00
\n",
"
60657041
\n",
"
232602
\n",
"
POLYGON ((-75.10323 40.71943, -75.06000 40.753...
\n",
"
\n",
"
\n",
"
4
\n",
"
17
\n",
"
17160
\n",
"
9500000US1717160
\n",
"
1717160
\n",
"
Gower School District 62
\n",
"
IL
\n",
"
Illinois
\n",
"
00
\n",
"
13484773
\n",
"
437292
\n",
"
POLYGON ((-87.96002 41.75215, -87.95929 41.752...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP ELSDLEA AFFGEOID GEOID \\\n",
"0 17 42570 9500000US1742570 1742570 \n",
"1 40 4470 9500000US4004470 4004470 \n",
"2 17 8790 9500000US1708790 1708790 \n",
"3 34 5520 9500000US3405520 3405520 \n",
"4 17 17160 9500000US1717160 1717160 \n",
"\n",
" NAME STUSPS STATE_NAME LSAD ALAND \\\n",
"0 Willow Springs School District 108 IL Illinois 00 24565916 \n",
"1 Bishop Public School OK Oklahoma 00 18936631 \n",
"2 Cass School District 63 IL Illinois 00 11006857 \n",
"3 Franklin Township School District NJ New Jersey 00 60657041 \n",
"4 Gower School District 62 IL Illinois 00 13484773 \n",
"\n",
" AWATER geometry \n",
"0 2685308 POLYGON ((-87.91426 41.71660, -87.90923 41.719... \n",
"1 0 POLYGON ((-98.44840 34.59449, -98.43973 34.594... \n",
"2 329296 POLYGON ((-88.00218 41.72823, -88.00230 41.729... \n",
"3 232602 POLYGON ((-75.10323 40.71943, -75.06000 40.753... \n",
"4 437292 POLYGON ((-87.96002 41.75215, -87.95929 41.752... "
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_elsd_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "572dc529",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select all the Elementary School Districts in Montana by filtering by `\"MT\"` in the STUSPS column."
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "2877414b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STUSPS == \"MT\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Montana Elementary School Districts\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "c23c6bd7",
"metadata": {},
"source": [
"The map created shows the Montana Elementary School Districts.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### School Districts - Secondary (SCSD)\n",
"\n",
"This file contains [Secondary School Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_23), referring to districts with secondary schools.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* SCDLEA = Secondary School District local education agency code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code and SCSDLEA code\n",
"* NAME = Secondary School District name\n",
"* STUSPS = FIPS Postal code. STATE_NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = Coordinates for Secondary School District polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Secondary School Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "bdb95310",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
SCSDLEA
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
06
\n",
"
99004
\n",
"
9600000US0699004
\n",
"
0699004
\n",
"
Sierra Unified School District (9-12)
\n",
"
CA
\n",
"
California
\n",
"
00
\n",
"
2950629174
\n",
"
63592439
\n",
"
POLYGON ((-119.40472 37.09651, -119.39820 37.0...
\n",
"
\n",
"
\n",
"
1
\n",
"
17
\n",
"
99001
\n",
"
9600000US1799001
\n",
"
1799001
\n",
"
Bluford Unit School District 318 (9-12) in Far...
\n",
"
IL
\n",
"
Illinois
\n",
"
00
\n",
"
99593597
\n",
"
219159
\n",
"
POLYGON ((-88.81637 38.38809, -88.81180 38.388...
\n",
"
\n",
"
\n",
"
2
\n",
"
17
\n",
"
33720
\n",
"
9600000US1733720
\n",
"
1733720
\n",
"
Ridgewood Community High School District 234
\n",
"
IL
\n",
"
Illinois
\n",
"
00
\n",
"
6948669
\n",
"
0
\n",
"
POLYGON ((-87.84656 41.96914, -87.84654 41.971...
\n",
"
\n",
"
\n",
"
3
\n",
"
06
\n",
"
21600
\n",
"
9600000US0621600
\n",
"
0621600
\n",
"
Liberty Union High School District
\n",
"
CA
\n",
"
California
\n",
"
00
\n",
"
504991993
\n",
"
61858554
\n",
"
POLYGON ((-121.83236 37.93557, -121.83236 37.9...
\n",
"
\n",
"
\n",
"
4
\n",
"
06
\n",
"
25150
\n",
"
9600000US0625150
\n",
"
0625150
\n",
"
Modesto City High School District
\n",
"
CA
\n",
"
California
\n",
"
00
\n",
"
430136526
\n",
"
3637374
\n",
"
POLYGON ((-121.24123 37.66425, -121.24003 37.6...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP SCSDLEA AFFGEOID GEOID \\\n",
"0 06 99004 9600000US0699004 0699004 \n",
"1 17 99001 9600000US1799001 1799001 \n",
"2 17 33720 9600000US1733720 1733720 \n",
"3 06 21600 9600000US0621600 0621600 \n",
"4 06 25150 9600000US0625150 0625150 \n",
"\n",
" NAME STUSPS STATE_NAME LSAD \\\n",
"0 Sierra Unified School District (9-12) CA California 00 \n",
"1 Bluford Unit School District 318 (9-12) in Far... IL Illinois 00 \n",
"2 Ridgewood Community High School District 234 IL Illinois 00 \n",
"3 Liberty Union High School District CA California 00 \n",
"4 Modesto City High School District CA California 00 \n",
"\n",
" ALAND AWATER geometry \n",
"0 2950629174 63592439 POLYGON ((-119.40472 37.09651, -119.39820 37.0... \n",
"1 99593597 219159 POLYGON ((-88.81637 38.38809, -88.81180 38.388... \n",
"2 6948669 0 POLYGON ((-87.84656 41.96914, -87.84654 41.971... \n",
"3 504991993 61858554 POLYGON ((-121.83236 37.93557, -121.83236 37.9... \n",
"4 430136526 3637374 POLYGON ((-121.24123 37.66425, -121.24003 37.6... "
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_scsd_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "0c23c7b1",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select all the Secondary School Districts in Arizona by filtering by `\"AZ\"` in the STUSPS column."
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "77bb0834",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STUSPS == \"AZ\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Arizona Secondary School Districts\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "0a723a9c",
"metadata": {},
"source": [
"The map created shows the Arizona Secondary School Districts.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### School Districts - Unified (UNSD)\n",
"\n",
"This file contains [Unified School Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_23), referring to districts that provide education to children of all school ages. Unified school districts can have both secondary and elementary schools.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* UNSDLEA = Unified School District local education agency code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code and UNSDLEA code\n",
"* NAME = Unified School District name\n",
"* STUSPS = FIPS Postal code\n",
"* STATE_NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = Coordinates for Unified School District polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Unified School Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "cc64d5bb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
UNSDLEA
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
36
\n",
"
18210
\n",
"
9700000US3618210
\n",
"
3618210
\n",
"
Malverne Union Free School District
\n",
"
NY
\n",
"
New York
\n",
"
00
\n",
"
5271104
\n",
"
539214
\n",
"
POLYGON ((-73.67603 40.67130, -73.67428 40.672...
\n",
"
\n",
"
\n",
"
1
\n",
"
29
\n",
"
21660
\n",
"
9700000US2921660
\n",
"
2921660
\n",
"
Northeast Nodaway County R-V School District
\n",
"
MO
\n",
"
Missouri
\n",
"
00
\n",
"
292199326
\n",
"
69164
\n",
"
POLYGON ((-94.78484 40.37451, -94.77798 40.373...
\n",
"
\n",
"
\n",
"
2
\n",
"
29
\n",
"
9930
\n",
"
9700000US2909930
\n",
"
2909930
\n",
"
Blair Oaks R-II School District
\n",
"
MO
\n",
"
Missouri
\n",
"
00
\n",
"
181982856
\n",
"
5337193
\n",
"
POLYGON ((-92.25955 38.37702, -92.25574 38.381...
\n",
"
\n",
"
\n",
"
3
\n",
"
29
\n",
"
11550
\n",
"
9700000US2911550
\n",
"
2911550
\n",
"
Cole County R-V School District
\n",
"
MO
\n",
"
Missouri
\n",
"
00
\n",
"
368295288
\n",
"
3182437
\n",
"
POLYGON ((-92.46801 38.31442, -92.46697 38.327...
\n",
"
\n",
"
\n",
"
4
\n",
"
51
\n",
"
2490
\n",
"
9700000US5102490
\n",
"
5102490
\n",
"
Middlesex County Public Schools
\n",
"
VA
\n",
"
Virginia
\n",
"
00
\n",
"
337554148
\n",
"
208310589
\n",
"
MULTIPOLYGON (((-76.42081 37.59787, -76.41957 ...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP UNSDLEA AFFGEOID GEOID \\\n",
"0 36 18210 9700000US3618210 3618210 \n",
"1 29 21660 9700000US2921660 2921660 \n",
"2 29 9930 9700000US2909930 2909930 \n",
"3 29 11550 9700000US2911550 2911550 \n",
"4 51 2490 9700000US5102490 5102490 \n",
"\n",
" NAME STUSPS STATE_NAME LSAD \\\n",
"0 Malverne Union Free School District NY New York 00 \n",
"1 Northeast Nodaway County R-V School District MO Missouri 00 \n",
"2 Blair Oaks R-II School District MO Missouri 00 \n",
"3 Cole County R-V School District MO Missouri 00 \n",
"4 Middlesex County Public Schools VA Virginia 00 \n",
"\n",
" ALAND AWATER geometry \n",
"0 5271104 539214 POLYGON ((-73.67603 40.67130, -73.67428 40.672... \n",
"1 292199326 69164 POLYGON ((-94.78484 40.37451, -94.77798 40.373... \n",
"2 181982856 5337193 POLYGON ((-92.25955 38.37702, -92.25574 38.381... \n",
"3 368295288 3182437 POLYGON ((-92.46801 38.31442, -92.46697 38.327... \n",
"4 337554148 208310589 MULTIPOLYGON (((-76.42081 37.59787, -76.41957 ... "
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_unsd_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "3f34d70b",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, select the entire New York City Unified School District, which encompasses the five counties of NYC. Select the relevant data by filtering by the NAME column."
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "680d0c72",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.NAME == \"New York City Department Of Education\"].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"New York City Unified School District\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "0e431844",
"metadata": {},
"source": [
"The map created shows the New York City Unified School District.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### State Legislative Districts\n",
"\n",
"[State Legislative Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_24) is the fourth grouping of datasets within the census data by cartographic boundaries group.\n",
"This dataset grouping includes State Legislative Districts for both Upper and Lower State Chambers. These are areas in which voters elect a person to represent them in state or equivalent entity legislatures. Most states have both upper and lower chambers, the exceptions being Nebraska which has a unicameral legislature, and Washington, DC, which has a single council. As a result, there is no lower house data for Nebraska and DC.\n",
"\n",
"#### State Legislative Districts - Lower Chamber (SLDL)\n",
"\n",
"\n",
"\n",
"This file contains [Lower Chamber State Legislative Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_24).\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* SLDLST = State Legislative District Lower Chamber code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code and SLDLST\n",
"* NAME = District Name\n",
"* NAMELSAD = District name and legal/statistical description\n",
"* STUSPS = FIPS Postal code\n",
"* STATE_NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* LSY = Legislative Session Year\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Lower Chamber polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Lower Chamber State Legislative Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "0f2ba2ef",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
SLDLST
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
LSY
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
37
\n",
"
067
\n",
"
620L600US37067
\n",
"
37067
\n",
"
67
\n",
"
State House District 67
\n",
"
NC
\n",
"
North Carolina
\n",
"
LL
\n",
"
2018
\n",
"
1372481845
\n",
"
13054913
\n",
"
POLYGON ((-80.67249 35.28457, -80.66859 35.284...
\n",
"
\n",
"
\n",
"
1
\n",
"
37
\n",
"
023
\n",
"
620L600US37023
\n",
"
37023
\n",
"
23
\n",
"
State House District 23
\n",
"
NC
\n",
"
North Carolina
\n",
"
LL
\n",
"
2018
\n",
"
2498112701
\n",
"
4460107
\n",
"
POLYGON ((-77.82844 35.86721, -77.82613 35.871...
\n",
"
\n",
"
\n",
"
2
\n",
"
39
\n",
"
078
\n",
"
620L600US39078
\n",
"
39078
\n",
"
78
\n",
"
State House District 78
\n",
"
OH
\n",
"
Ohio
\n",
"
LL
\n",
"
2018
\n",
"
3609975942
\n",
"
28657516
\n",
"
POLYGON ((-83.01738 39.73643, -83.01428 39.738...
\n",
"
\n",
"
\n",
"
3
\n",
"
41
\n",
"
026
\n",
"
620L600US41026
\n",
"
41026
\n",
"
26
\n",
"
State House District 26
\n",
"
OR
\n",
"
Oregon
\n",
"
LL
\n",
"
2018
\n",
"
209051898
\n",
"
1046849
\n",
"
POLYGON ((-122.95072 45.44942, -122.94726 45.4...
\n",
"
\n",
"
\n",
"
4
\n",
"
41
\n",
"
015
\n",
"
620L600US41015
\n",
"
41015
\n",
"
15
\n",
"
State House District 15
\n",
"
OR
\n",
"
Oregon
\n",
"
LL
\n",
"
2018
\n",
"
517343089
\n",
"
8286102
\n",
"
POLYGON ((-123.26079 44.55749, -123.26025 44.5...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP SLDLST AFFGEOID GEOID NAME NAMELSAD STUSPS \\\n",
"0 37 067 620L600US37067 37067 67 State House District 67 NC \n",
"1 37 023 620L600US37023 37023 23 State House District 23 NC \n",
"2 39 078 620L600US39078 39078 78 State House District 78 OH \n",
"3 41 026 620L600US41026 41026 26 State House District 26 OR \n",
"4 41 015 620L600US41015 41015 15 State House District 15 OR \n",
"\n",
" STATE_NAME LSAD LSY ALAND AWATER \\\n",
"0 North Carolina LL 2018 1372481845 13054913 \n",
"1 North Carolina LL 2018 2498112701 4460107 \n",
"2 Ohio LL 2018 3609975942 28657516 \n",
"3 Oregon LL 2018 209051898 1046849 \n",
"4 Oregon LL 2018 517343089 8286102 \n",
"\n",
" geometry \n",
"0 POLYGON ((-80.67249 35.28457, -80.66859 35.284... \n",
"1 POLYGON ((-77.82844 35.86721, -77.82613 35.871... \n",
"2 POLYGON ((-83.01738 39.73643, -83.01428 39.738... \n",
"3 POLYGON ((-122.95072 45.44942, -122.94726 45.4... \n",
"4 POLYGON ((-123.26079 44.55749, -123.26025 44.5... "
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_sldl_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "5e7bce31",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, plot all the Lower Chamber State Legislative Districts in Texas by filtering by `\"TX\"` in the STUSPS column."
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "1f1efc89",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STUSPS == \"TX\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"State Legislative Districts: Texas, Lower Chamber\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "6290c0fb",
"metadata": {},
"source": [
"The map created shows the Texas Lower Chamber State Legislative Districts.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"#### State Legislative Districts - Upper Chamber (SLDU)\n",
"\n",
"This file contains [Upper Chamber State Legislative Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_24).\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* SLDUST = State Legislative District Upper Chamber code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code and SLDUST\n",
"* NAME = District Name\n",
"* NAMELSAD = District name and legal/statistical description\n",
"* STUSPS = FIPS Postal code\n",
"* STATE_NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* LSY = Legislative Session Year\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Upper Chamber polygon\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Upper Chamber State Legislative Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "6deca758",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
SLDUST
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
STUSPS
\n",
"
STATE_NAME
\n",
"
LSAD
\n",
"
LSY
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
41
\n",
"
004
\n",
"
610U600US41004
\n",
"
41004
\n",
"
4
\n",
"
State Senate District 4
\n",
"
OR
\n",
"
Oregon
\n",
"
LU
\n",
"
2018
\n",
"
16139528745
\n",
"
167874360
\n",
"
POLYGON ((-123.81715 43.45959, -123.81666 43.5...
\n",
"
\n",
"
\n",
"
1
\n",
"
41
\n",
"
015
\n",
"
610U600US41015
\n",
"
41015
\n",
"
15
\n",
"
State Senate District 15
\n",
"
OR
\n",
"
Oregon
\n",
"
LU
\n",
"
2018
\n",
"
238454422
\n",
"
423501
\n",
"
POLYGON ((-123.15350 45.53457, -123.15271 45.5...
\n",
"
\n",
"
\n",
"
2
\n",
"
42
\n",
"
016
\n",
"
610U600US42016
\n",
"
42016
\n",
"
16
\n",
"
State Senate District 16
\n",
"
PA
\n",
"
Pennsylvania
\n",
"
LU
\n",
"
2018
\n",
"
796458250
\n",
"
5947856
\n",
"
POLYGON ((-75.88921 40.67834, -75.85481 40.693...
\n",
"
\n",
"
\n",
"
3
\n",
"
48
\n",
"
015
\n",
"
610U600US48015
\n",
"
48015
\n",
"
15
\n",
"
State Senate District 15
\n",
"
TX
\n",
"
Texas
\n",
"
LU
\n",
"
2018
\n",
"
828734514
\n",
"
37403360
\n",
"
POLYGON ((-95.57473 29.86719, -95.56919 29.867...
\n",
"
\n",
"
\n",
"
4
\n",
"
51
\n",
"
016
\n",
"
610U600US51016
\n",
"
51016
\n",
"
16
\n",
"
State Senate District 16
\n",
"
VA
\n",
"
Virginia
\n",
"
LU
\n",
"
2018
\n",
"
580535957
\n",
"
32576935
\n",
"
POLYGON ((-77.59806 37.23679, -77.59600 37.238...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP SLDUST AFFGEOID GEOID NAME NAMELSAD STUSPS \\\n",
"0 41 004 610U600US41004 41004 4 State Senate District 4 OR \n",
"1 41 015 610U600US41015 41015 15 State Senate District 15 OR \n",
"2 42 016 610U600US42016 42016 16 State Senate District 16 PA \n",
"3 48 015 610U600US48015 48015 15 State Senate District 15 TX \n",
"4 51 016 610U600US51016 51016 16 State Senate District 16 VA \n",
"\n",
" STATE_NAME LSAD LSY ALAND AWATER \\\n",
"0 Oregon LU 2018 16139528745 167874360 \n",
"1 Oregon LU 2018 238454422 423501 \n",
"2 Pennsylvania LU 2018 796458250 5947856 \n",
"3 Texas LU 2018 828734514 37403360 \n",
"4 Virginia LU 2018 580535957 32576935 \n",
"\n",
" geometry \n",
"0 POLYGON ((-123.81715 43.45959, -123.81666 43.5... \n",
"1 POLYGON ((-123.15350 45.53457, -123.15271 45.5... \n",
"2 POLYGON ((-75.88921 40.67834, -75.85481 40.693... \n",
"3 POLYGON ((-95.57473 29.86719, -95.56919 29.867... \n",
"4 POLYGON ((-77.59806 37.23679, -77.59600 37.238... "
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_sldu_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "24a682ea",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, plot all the Upper Chamber State Legislative Districts in Michigan by filtering by `\"MI\"` in the STUSPS column."
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "75b59748",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.STUSPS == \"MI\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"State Legislative Districts: Michigan, Upper Chamber\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "7c65ccf4",
"metadata": {},
"source": [
"The map created shows the Michigan Upper Chamber State Legislative Districts.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### States (STATE)\n",
"\n",
"This file contains the [US States and State Equivalent Entities](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_25). Within Census Bureau datasets, the District of Columbia, Puerto Rico, and the Island Areas (American Samoa, the Commonwealth of the Northern Mariana Islands, Guam, and the US Virgin Islands) are treated as statistical equivalents of states alongside the 50 US states.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* STATENS = State ANSI feature code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = STATEFP\n",
"* STUSPS = FIPS postal code\n",
"* NAME = State name\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for State polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the US States and State Equivalent Entities data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "efcce466",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
STATENS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
STUSPS
\n",
"
NAME
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
66
\n",
"
1802705
\n",
"
0400000US66
\n",
"
66
\n",
"
GU
\n",
"
Guam
\n",
"
00
\n",
"
543555847
\n",
"
934337453
\n",
"
MULTIPOLYGON (((144.64538 13.23627, 144.64716 ...
\n",
"
\n",
"
\n",
"
1
\n",
"
48
\n",
"
1779801
\n",
"
0400000US48
\n",
"
48
\n",
"
TX
\n",
"
Texas
\n",
"
00
\n",
"
676680588914
\n",
"
18979352230
\n",
"
MULTIPOLYGON (((-94.71830 29.72885, -94.71721 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
55
\n",
"
1779806
\n",
"
0400000US55
\n",
"
55
\n",
"
WI
\n",
"
Wisconsin
\n",
"
00
\n",
"
140292246684
\n",
"
29343721650
\n",
"
MULTIPOLYGON (((-86.95617 45.35549, -86.95463 ...
\n",
"
\n",
"
\n",
"
3
\n",
"
44
\n",
"
1219835
\n",
"
0400000US44
\n",
"
44
\n",
"
RI
\n",
"
Rhode Island
\n",
"
00
\n",
"
2677759219
\n",
"
1323691129
\n",
"
MULTIPOLYGON (((-71.28802 41.64558, -71.28647 ...
\n",
"
\n",
"
\n",
"
4
\n",
"
36
\n",
"
1779796
\n",
"
0400000US36
\n",
"
36
\n",
"
NY
\n",
"
New York
\n",
"
00
\n",
"
122049520861
\n",
"
19256750161
\n",
"
MULTIPOLYGON (((-72.03683 41.24984, -72.03496 ...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND \\\n",
"0 66 1802705 0400000US66 66 GU Guam 00 543555847 \n",
"1 48 1779801 0400000US48 48 TX Texas 00 676680588914 \n",
"2 55 1779806 0400000US55 55 WI Wisconsin 00 140292246684 \n",
"3 44 1219835 0400000US44 44 RI Rhode Island 00 2677759219 \n",
"4 36 1779796 0400000US36 36 NY New York 00 122049520861 \n",
"\n",
" AWATER geometry \n",
"0 934337453 MULTIPOLYGON (((144.64538 13.23627, 144.64716 ... \n",
"1 18979352230 MULTIPOLYGON (((-94.71830 29.72885, -94.71721 ... \n",
"2 29343721650 MULTIPOLYGON (((-86.95617 45.35549, -86.95463 ... \n",
"3 1323691129 MULTIPOLYGON (((-71.28802 41.64558, -71.28647 ... \n",
"4 19256750161 MULTIPOLYGON (((-72.03683 41.24984, -72.03496 ... "
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_state_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "91558478",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, plot only the contiguous US, Puerto Rico, and the US Virgin Islands. To exclude parts of the dataset from plotting, use `~df.STATEFP.isin()` to exclude the STATEFP codes for Alaska, Hawaii, Guam, American Samoa, and the Commonwealth of the Northern Mariana Islands."
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "2ab8d3e1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[~ddf.STATEFP.isin([\"02\", \"15\", \"60\", \"66\", \"69\"])].plot(\n",
" figsize=(10, 10), alpha=0.5, edgecolor=\"k\"\n",
")\n",
"ax.set_title(\n",
" \"States: Contiguous US, Puerto Rico, & USVI\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "f703c692",
"metadata": {},
"source": [
"The map created shows the Contiguous US, Puerto Rico, and the US Virgin Islands.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Subbarrios (SUBBARRIO)\n",
"\n",
"This file contains [Subbarrios](https://www.census.gov/programs-surveys/geography/about/glossary.html#pr), which are legally defined subdivisions of Minor Civil Division in Puerto Rico. They don\"t exist within every Minor Civil Division and don\"t always cover the entire Minor Civil Division where they do exist.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP = State FIPS code\n",
"* COUNTYFP = County FIPS code\n",
"* COUSUBFP = County Subdivision FIPS code\n",
"* SUBMCDFP = Subbarrio FIPS code\n",
"* SUBMCDNS = Subbarrio ANSI feature code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* GEOID = Concatenation of State FIPS code, County FIPS code, County Subdivision FIPS code and Subbarrio FIPS code\n",
"* NAME = Subbarrio name\n",
"* NAMELSAD = Subbarrio name and legal/statistical division\n",
"* LSAD = Legal/statistical classification\n",
"* ALAND = Current land area\n",
"* AWATER = Current water area\n",
"* geometry = coordinates for Subbarrio polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Subbarrios data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "0c1dce9b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP
\n",
"
COUNTYFP
\n",
"
COUSUBFP
\n",
"
SUBMCDFP
\n",
"
SUBMCDNS
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
NAMELSAD
\n",
"
LSAD
\n",
"
ALAND
\n",
"
AWATER
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
72
\n",
"
035
\n",
"
15537
\n",
"
65040
\n",
"
2415842
\n",
"
0670000US720351553765040
\n",
"
720351553765040
\n",
"
Pueblo Sur
\n",
"
Pueblo Sur subbarrio
\n",
"
51
\n",
"
2708525
\n",
"
517
\n",
"
POLYGON ((-66.18201 18.11012, -66.18182 18.110...
\n",
"
\n",
"
\n",
"
1
\n",
"
72
\n",
"
127
\n",
"
84079
\n",
"
84771
\n",
"
2416087
\n",
"
0670000US721278407984771
\n",
"
721278407984771
\n",
"
Valencia
\n",
"
Valencia subbarrio
\n",
"
51
\n",
"
144073
\n",
"
0
\n",
"
POLYGON ((-66.04345 18.41148, -66.04334 18.411...
\n",
"
\n",
"
\n",
"
2
\n",
"
72
\n",
"
127
\n",
"
79693
\n",
"
34770
\n",
"
2415499
\n",
"
0670000US721277969334770
\n",
"
721277969334770
\n",
"
Hipódromo
\n",
"
Hipódromo subbarrio
\n",
"
51
\n",
"
263788
\n",
"
0
\n",
"
POLYGON ((-66.07415 18.44463, -66.07115 18.448...
\n",
"
\n",
"
\n",
"
3
\n",
"
72
\n",
"
013
\n",
"
03411
\n",
"
72325
\n",
"
2415953
\n",
"
0670000US720130341172325
\n",
"
720130341172325
\n",
"
Rosario
\n",
"
Rosario subbarrio
\n",
"
51
\n",
"
58332
\n",
"
12520
\n",
"
POLYGON ((-66.71531 18.47233, -66.71231 18.472...
\n",
"
\n",
"
\n",
"
4
\n",
"
72
\n",
"
121
\n",
"
73587
\n",
"
64805
\n",
"
2415826
\n",
"
0670000US721217358764805
\n",
"
721217358764805
\n",
"
Pueblo Norte
\n",
"
Pueblo Norte subbarrio
\n",
"
51
\n",
"
120549
\n",
"
0
\n",
"
POLYGON ((-66.96232 18.07969, -66.96186 18.080...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP COUNTYFP COUSUBFP SUBMCDFP SUBMCDNS AFFGEOID \\\n",
"0 72 035 15537 65040 2415842 0670000US720351553765040 \n",
"1 72 127 84079 84771 2416087 0670000US721278407984771 \n",
"2 72 127 79693 34770 2415499 0670000US721277969334770 \n",
"3 72 013 03411 72325 2415953 0670000US720130341172325 \n",
"4 72 121 73587 64805 2415826 0670000US721217358764805 \n",
"\n",
" GEOID NAME NAMELSAD LSAD ALAND \\\n",
"0 720351553765040 Pueblo Sur Pueblo Sur subbarrio 51 2708525 \n",
"1 721278407984771 Valencia Valencia subbarrio 51 144073 \n",
"2 721277969334770 Hipódromo Hipódromo subbarrio 51 263788 \n",
"3 720130341172325 Rosario Rosario subbarrio 51 58332 \n",
"4 721217358764805 Pueblo Norte Pueblo Norte subbarrio 51 120549 \n",
"\n",
" AWATER geometry \n",
"0 517 POLYGON ((-66.18201 18.11012, -66.18182 18.110... \n",
"1 0 POLYGON ((-66.04345 18.41148, -66.04334 18.411... \n",
"2 0 POLYGON ((-66.07415 18.44463, -66.07115 18.448... \n",
"3 12520 POLYGON ((-66.71531 18.47233, -66.71231 18.472... \n",
"4 0 POLYGON ((-66.96232 18.07969, -66.96186 18.080... "
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_72_subbarrio_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "b5ca2686",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, plot all the Subbarrios in the San Juan Municipo (the county equivalent for Puerto Rico). Select the relevant data by filtering by the COUNTYFP column."
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "2ca3f29c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf[ddf.COUNTYFP == \"127\"].plot(figsize=(10, 10), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"Subbarrios: San Juan, Puerto Rico\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "2bda7eae",
"metadata": {},
"source": [
"The map created shows the Subbarrios in San Juan Municipo.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### United States Outline\n",
"\n",
"This file contains the [United States Outline](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_30) shapefile. This contains all 50 US states plus the District of Columbia, Puerto Rico, and the Island Areas (American Samoa, the Commonwealth of the Northern Mariana Islands, Guam, and the US Virgin Islands). There is only one feature within this dataset.\n",
"\n",
"The attribute table for this dataset only contains the AFFGEOID, GEOID, NAME, and coordinates for the US polygon.\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the United States Outline data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "064bb555",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
AFFGEOID
\n",
"
GEOID
\n",
"
NAME
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
0100000US
\n",
"
US
\n",
"
United States
\n",
"
MULTIPOLYGON (((179.48246 51.98283, 179.48656 ...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" AFFGEOID GEOID NAME \\\n",
"0 0100000US US United States \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((179.48246 51.98283, 179.48656 ... "
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_nation_5m\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "fccb8907",
"metadata": {},
"source": [
"Next, plot the entire data from this parquet file and overlay it on a basemap. Since this dataset contains only one feature, there are no options to select or exclude specific parts based on attributes."
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "a3cb3236",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"
"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ddf.crs = 4326\n",
"ddf = ddf.to_crs(epsg=3857)\n",
"\n",
"ax = ddf.plot(figsize=(30, 60), alpha=0.5, edgecolor=\"k\")\n",
"ax.set_title(\n",
" \"United States and US Overseas Territories\",\n",
" fontdict={\"fontsize\": \"20\", \"fontweight\": \"2\"},\n",
")\n",
"ctx.add_basemap(ax, source=ctx.providers.Esri.NatGeoWorldMap)\n",
"ax.set_axis_off()"
]
},
{
"cell_type": "markdown",
"id": "85e4992f",
"metadata": {},
"source": [
"The map created shows the United States and US Overseas Territories.\n",
"\n",
"**[Jump to Top](#United-States-2020-Census-data)**\n",
"\n",
"### Voting Districts (VTD)\n",
"\n",
"This file contains all [US Voting Districts](https://www.census.gov/programs-surveys/geography/about/glossary.html#par_textimage_31), which are geographic features established by state, local and tribal governments to conduct elections.\n",
"\n",
"The attribute table contains the following information:\n",
"\n",
"* STATEFP20 = State FIPS code\n",
"* COUNTYFP20 = County FIPS code\n",
"* VTDST20 = Voting district code\n",
"* AFFGEOID = American FactFinder summary level code + geovariant code + \"00US\" + GEOID\n",
"* EOID = Concatenation of State FIPS code, County FIPS code, and Voting District code\n",
"* VTDI20 = Voting district indicator\n",
"* NAME20 = Voting district name\n",
"* NAMELSAD20 = Voting district name and legal/statistical division\n",
"* LSAD20 = Legal/statistical classification\n",
"* ALAND20 = Current land area\n",
"* AWATER20 = Current water area\n",
"* geometry = coordinates for Voting District polygons\n",
"\n",
"Use the [read_parquet](https://geopandas.readthedocs.io/en/latest/docs/reference/api/geopandas.read_parquet.html) function of [Dask-GeoPandas](https://github.com/geopandas/dask-geopandas) to read the Voting Districts data from the parquet file of the Planetary Computer dataset:"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "32919257",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
STATEFP20
\n",
"
COUNTYFP20
\n",
"
VTDST20
\n",
"
AFFGEOID20
\n",
"
GEOID20
\n",
"
VTDI20
\n",
"
NAME20
\n",
"
NAMELSAD20
\n",
"
LSAD20
\n",
"
ALAND20
\n",
"
AWATER20
\n",
"
geometry
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
24
\n",
"
003
\n",
"
06-024
\n",
"
7000000US2400306-024
\n",
"
2400306-024
\n",
"
A
\n",
"
ANNE ARUNDEL PRECINCT 06-024
\n",
"
ANNE ARUNDEL PRECINCT 06-024
\n",
"
00
\n",
"
2756767
\n",
"
21979454
\n",
"
POLYGON ((-76.48621 38.92784, -76.48142 38.928...
\n",
"
\n",
"
\n",
"
1
\n",
"
24
\n",
"
047
\n",
"
01-002
\n",
"
7000000US2404701-002
\n",
"
2404701-002
\n",
"
A
\n",
"
WORCESTER PRECINCT 01-002
\n",
"
WORCESTER PRECINCT 01-002
\n",
"
00
\n",
"
111861087
\n",
"
1934368
\n",
"
MULTIPOLYGON (((-75.30048 38.09594, -75.29902 ...
\n",
"
\n",
"
\n",
"
2
\n",
"
02
\n",
"
090
\n",
"
06-150
\n",
"
7000000US0209006-150
\n",
"
0209006-150
\n",
"
A
\n",
"
Fox Precinct
\n",
"
Fox Precinct
\n",
"
00
\n",
"
2241567797
\n",
"
0
\n",
"
POLYGON ((-148.11011 65.20532, -148.10451 65.2...
\n",
"
\n",
"
\n",
"
3
\n",
"
26
\n",
"
101
\n",
"
101001
\n",
"
7000000US26101101001
\n",
"
26101101001
\n",
"
A
\n",
"
1010332000001
\n",
"
Voting District 1010332000001
\n",
"
V1
\n",
"
48159260
\n",
"
1006220
\n",
"
POLYGON ((-86.25160 44.46544, -86.25091 44.469...
\n",
"
\n",
"
\n",
"
4
\n",
"
26
\n",
"
055
\n",
"
055007
\n",
"
7000000US26055055007
\n",
"
26055055007
\n",
"
A
\n",
"
0552380000001
\n",
"
Voting District 0552380000001
\n",
"
V1
\n",
"
9967698
\n",
"
0
\n",
"
POLYGON ((-85.57537 44.75340, -85.57330 44.752...
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" STATEFP20 COUNTYFP20 VTDST20 AFFGEOID20 GEOID20 VTDI20 \\\n",
"0 24 003 06-024 7000000US2400306-024 2400306-024 A \n",
"1 24 047 01-002 7000000US2404701-002 2404701-002 A \n",
"2 02 090 06-150 7000000US0209006-150 0209006-150 A \n",
"3 26 101 101001 7000000US26101101001 26101101001 A \n",
"4 26 055 055007 7000000US26055055007 26055055007 A \n",
"\n",
" NAME20 NAMELSAD20 LSAD20 \\\n",
"0 ANNE ARUNDEL PRECINCT 06-024 ANNE ARUNDEL PRECINCT 06-024 00 \n",
"1 WORCESTER PRECINCT 01-002 WORCESTER PRECINCT 01-002 00 \n",
"2 Fox Precinct Fox Precinct 00 \n",
"3 1010332000001 Voting District 1010332000001 V1 \n",
"4 0552380000001 Voting District 0552380000001 V1 \n",
"\n",
" ALAND20 AWATER20 geometry \n",
"0 2756767 21979454 POLYGON ((-76.48621 38.92784, -76.48142 38.928... \n",
"1 111861087 1934368 MULTIPOLYGON (((-75.30048 38.09594, -75.29902 ... \n",
"2 2241567797 0 POLYGON ((-148.11011 65.20532, -148.10451 65.2... \n",
"3 48159260 1006220 POLYGON ((-86.25160 44.46544, -86.25091 44.469... \n",
"4 9967698 0 POLYGON ((-85.57537 44.75340, -85.57330 44.752... "
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asset = census.get_item(\"2020-cb_2020_us_vtd_500k\").assets[\"data\"]\n",
"ddf = geopandas.read_parquet(\n",
" asset.href, storage_options=asset.extra_fields[\"table:storage_options\"]\n",
")\n",
"ddf.head()"
]
},
{
"cell_type": "markdown",
"id": "d9a1babf",
"metadata": {},
"source": [
"Next, plot the data from this parquet file and overlay it on a basemap. For this example, plot all the Voting Districts in Salt Lake City, UT by filtering by Voting District Names that begin with `\"Salt Lake\"` in the NAME20 column."
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "20151b95",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"