Accessing 2020 Census Redistricting Data Through The Census Data API: Single Estimates
Accessing 2020 Census Redistricting Data Through The Census Data API: Single Estimates
Estimates
Transcript
September 2021
Hi, my name is Deb. The Census Bureau offers data users different ways to access
2020 Redistricting Data. For more advanced users, one of the ways to extract PL 94-171
data is through the Census Data Application Programming Interface, or as it’s
commonly referred to, the Census API. The Census API data service, provides data
users access to Census data for purposes of research, creating custom visualizations,
or for developers to create mobile or web applications.
In this video my colleague Jessica Barnett will help you learn some core concepts and
steps to quickly and easily pull individual estimates for Redistricting Data using the
Census API.
Hi, I’m Jessica and I work in the Dissemination Outreach Branch. Today I want to show
you how to access 2020 Public Law 94-171 Redistricting Data through the Census
Application Programming Interface, or API.
Public Law, or P.L., 94-171, requires that the Census Bureau provide states the
opportunity to identify the geographic areas for which specific population tabulations
are needed and provide those tabulations to states in a timely manner for the purpose
of redistricting. We’ve developed this video tutorial to help you find the P.L. 94-171
Redistricting Data using the Census API.
In the event that you do not already have any data in mind to use from the P.L. 94-171
Redistricting Data, you may want to take a look at what’s available. My colleague, Maria,
put together some video tutorials that cover how to find all of the 2020 P.L. 94-171
Redistricting Data tables that are found in data.census.gov. If you want to find out
what’s available, please check them out on our Resources page, which is linked below.
Let’s say that I want to find the population total for people who are of one race for the
state of Indiana. When I look in data.census.gov, this information is provided in table
P1. However, as we can see, table P1 is a pretty big table, and I only need data for this
top portion of the table, for the population of one race for each race group in Indiana.
Ideally, I would be able to filter out everything except for the handful of rows of data that
I need. This happens to be one of the benefits in using the Census API – if I want, I can
pull data for the variables that I need, instead of pulling data for the entire table.
So how would I accomplish this using the Census API? First, we need to access the
2020 Decennial Census API. We’ll use our API Discovery Tool to do this. Go to
https://www.census.gov/data/developers.html. Then at the top, under the Developers
heading, click on the link to the Discovery Tool. You have three different options for
using the API Discovery Tool. I prefer to use the html version, so click on the first link-
Accessing 2020 Census Redistricting Data Through the Census Data API: Single
Estimates
Transcript
September 2021
the one for api.census.gov/data.html. This lists every dataset that’s available through
the API, for every year that it’s available. That makes for a lot of data! Let’s hit the Ctrl
and F keys to open the search functionality and search for Redistricting. The first
matches are for the 2000 Redistricting Data. Let’s click through those. Then we get to
the 2010 Redistricting Data, and we’ll continue to click through those. Finally we’ll reach
the 2020 Redistricting Data. It should say Decennial Census: Redistricting Data (PL 94-
171) in the very first column and 2020 in the third column.
Now let me show you a little trick for isolating the information for the dataset that you
want, rather than having to go through this each time you want to go to the 2020
Redistricting Data. In the fourth column, you’ll see that it says dec, pl, separated by a
greater-than sign. We’ll use this information to isolate the dataset. Navigate up to the
top of the screen, put the cursor right after the word ‘data,’ and enter a forward slash.
Then type in 2020, which represents the year that we are using, and then /dec/pl. Once
you are done, the URL should say api.census.gov/data/2020/dec/pl.html. Hit Enter.
Now you just have the API information that’s directly related to the 2020 Redistricting
Data showing on the screen.
Let’s take a moment to go over the different links that are available for this API. The
first link is for geographies. If you click on that, you’ll find all the geographies that the
2020 Redistricting Data is available for. We happen to need data for Indiana, and we
can see from the fourth line that this data is available for states.
If we click on the back arrow, and then click on the variables link, we’ll find all of the
variables that are available in the 2020 Redistricting Data. Let’s make a mental note
about this page, as we will come back to it shortly in order to find the variables that we
need.
For now, let’s click on the back arrow and click on the groups link. This lists the six
tables that are available from the 2020 Redistricting Data. Knowing this information is
useful if you wanted to pull an entire table, like all of P1, rather than one or more
individual pieces of data.
Let’s click on the back arrow again and move on to the examples link. This page is
extremely helpful because it provides you with example API queries that you can use for
each available geography. We’ll take a closer look at this page again soon.
Click on the back arrow again and click on the documentation link. This will take you
back to the Developers page where you can find more information on the Census API.
Accessing 2020 Census Redistricting Data Through the Census Data API: Single
Estimates
Transcript
September 2021
And, if we click on the back arrow a final time, we’ll see the base API query that is used
for the 2020 Redistricting Data. As you use this Redistricting Data API, you’ll notice that
every API query starts with this same base URL.
Now let’s get into actually using the API. Navigate back over a few columns and click
on the same variables link that we selected earlier. Again, this is showing us all of the
individual variables that are available for selection from the 2020 Redistricting Data API.
We already know that we want the variables that are associated with one race. In
particular, we’re looking for the total number of people who reported one race and the
total number of people who reported being White alone, Black or African American
alone, American Indian and Alaska Native alone, Asian alone, Native Hawaiian and Other
Pacific Islander alone, or Some Other Race alone-altogether, we’re looking for seven
individual numbers. If we look at the variables page again-particularly the right-most
Group column--and scroll down, we’ll come to the section of variables found in table P1.
This looks promising, so let’s take a closer look.
The first variable is P1_001N, which represents the total number of people. The ‘001’
portion of this variable name indicates that it will provide results for the first row of data
in the table, and the ‘P1’ portion indicates that this is for table P1. If we look back at the
table in data.census.gov, we’d see that this is the variable for the very first line of the
table. This is definitely important data, but it’s not one of the numbers that we are
specifically looking for.
Returning to the list of available variables, we can see that the next variable is P1_002N,
which is for the total population of one race. This does happen to be one of the
variables that we want, so I’m going to make a note of that variable name, P1_002N. If I
continue to look down the variable list, I can see that variables P1_003N through
P1_008N are the other variables that we want to use. Each of these provides data on a
different ‘alone’ race group. Just to confirm, if we look at P1_009N, we can see that it’s
the total for people who reported two or more races, and that’s not data that we need.
So now that we have the seven variables that we need that represent the numbers that
we want from the table--P1_002N through P1_008N--let’s jot them down.
Now that we have those noted, let’s hit the back arrow and click on the examples link-
again, this is one that we clicked on earlier. We need this data for Indiana, so we’re
looking for the state geography. Lucky for us, this happens to be close to the top of this
page, in the fourth section labeled ‘state’. As we can see, there are two example API
queries in this state section. The first one includes an asterisk. When looking at API
queries, an asterisk indicates that all geographies will be included. In other words, when
Accessing 2020 Census Redistricting Data Through the Census Data API: Single
Estimates
Transcript
September 2021
we see that this particular query includes &for=state with the asterisk, we know that it
will run the requested query and return data for all the states in the US.
The second query, on the other hand, does not have an asterisk, but instead has a two-
digit number. This two-digit number is the state Federal Information Processing
System, or FIPS, code. The state FIPS code included in this query, 06, is the code for
California. We need to find the state FIPS code for Indiana, though. The easiest way to
do this is to run the first query-the one with the asterisk. Let’s right click on that and
click ‘Open link in new tab.’ Now we can see a list of all the states and each one has a
two-digit code next to it. This two-digit code is the state FIPS code. We can confirm
this by looking at California-the code next to it is ’06.’ Let’s find Indiana…and it looks like
the state FIPS code for that is 18, so let’s make a note of it.
I’d like to note that you can also find a complete list of FIPS codes by going to our
geographic reference files, which are linked below.
Let’s return to the API examples page that we were looking at earlier. Since we just
want Indiana, it makes more sense to use the second API query where we’ll enter the
single state FIPS code, rather than use the first query which would give us data for all
the states in the US. So let’s right click on the second query and select ‘Open link in new
tab.’ As you can see, it has opened the query in a new tab and we already have output
available. As it stands, this query is just giving us the name of the state, along with the
state FIPS code, and not any data.
Modifying the query to include the variables we need is pretty easy, though. Go to the
get= portion of the URL and put the cursor right in front of the NAME variable. Type in
the variable names, all separated by commas-make sure you don’t include any spaces-
and then add a comma after the last variable name in order to separate it from the
NAME portion. For the sake of time, I’ve already copied the variables that we need and I
can quickly paste them into the URL. As you can see, when we finish, this portion of the
query reads
get=P1_002N,P1_003N,P1_004N,P1_005N,P1_006N,P1_007N,P1_008N,NAME. The
geography portion reads &for=state:06.
Now let’s hit Enter just to make sure the query is still running correctly and giving us the
data that we are expecting. And it looks like it worked just fine-we have all seven
numbers. But these are still for the state of California. We need to change it to Indiana.
Let’s navigate back up to the API query and replace ‘06’ with ‘18’, which is the state FIPS
Accessing 2020 Census Redistricting Data Through the Census Data API: Single
Estimates
Transcript
September 2021
code that we determined earlier is for Indiana. Once we’ve changed that, let’s hit Enter
again.
Now we can see that we have all seven numbers for Indiana. The first number is
6,348,802, which is the total number of people who reported one race (which
corresponds to variable P1_002N); 5,241,795 is the total number of people who reported
being White alone (which corresponds to variable P1_003N); 648,513 is the total
number of people who reported being Black or African American alone (which
corresponds to variable P1_004N); and so on. We end with the number for P1_008N,
261,312, which is the total number of people who reported Some Other Race alone.
Then we have the name of the geography we’re looking at, which is Indiana, along with
the state FIPS code for Indiana, which is 18.
Now that we have this data for Indiana, let’s say that we need data for the same
variables, but for a different geography, like all the blocks in Rhode Island. Since we’ve
already prepared the query for Indiana, the only thing that we’ll need to do at this point is
swap out the geography portion of the API query-this is the part that says
‘&for=state:18’.
Let’s go back to the 2020 Redistricting Data API examples page-the one found at
api.census.gov/data/2020/dec/pl/examples.html. We need to look for the queries for
blocks. It happens to be the eighth section from the top, labeled as ‘state > county >
tract > block.’ Whereas we only had two queries to choose from for states, we now
have four queries for blocks. Although there may not immediately look like there are a
lot differences between them, there are differences.
The first query is going to give you all the blocks in a particular county within a particular
state. The next one will also give all of the blocks, but they will be for all counties within
a particular state.
The third query is almost identical to the first one, in that it will provide data for all the
blocks in a particular county within a particular state, and, as it is currently defined, it will
actually run the same data. There are instances where using one of these queries over
the other is preferable, but we won’t cover that right now. Moving on to the fourth and
final query, this one will run data for one specific block in a particular tract found within
the given county and state.
Comparing these queries against our need for data on all the blocks in Rhode Island, it
looks like we’ll want to use the second query which will provide data on all blocks in all
counties within a state. Let’s right click on this second query and select ‘Open link in
Accessing 2020 Census Redistricting Data Through the Census Data API: Single
Estimates
Transcript
September 2021
new tab.’ Once it’s done running, we can see that it provides the names of the different
blocks in California-and we know it’s California because it’s using the state FIPS code of
’06.’
Recall that we still have the query open that we used to get data for the state of Indiana
and all we really need from this block query is the geography portion. To grab this,
highlight the portion of the URL that begins with ‘&for=block’ in its entirety, all the way
down to ‘&in=tract:*’, right click on it, and hit Copy.
Now let’s go back to the query that we were using earlier for Indiana. Highlight the very
last part of the URL, the part that says ‘&for=state:18’, right click on it, and hit paste.
This should swap out the old ‘for’ statement for Indiana with this new portion that’s
currently for blocks in California. For now, you can just click out of it and it shouldn’t
start running. If it does start running the query though, don’t worry-just let it run, and
once it’s done running, you can continue with modifying the query. We can see that this
is still for California, so we need to change it to the state FIPS code for Rhode Island.
Using the API query that we ran earlier that provided us with each state and its
respective FIPS code, I can see that the FIPS code for Rhode Island is 44. So now let’s
go back to our query and change the ‘06’ portion to ’44.’ Once that’s changed, now we
can hit Enter to run the query. It may take a few moments longer to run this query than
it took to run the last one for Indiana, given that we are looking for more information.
However, once it’s done, you can see that it’s provided data for all the same variables
that we wanted for all the blocks in Rhode Island. Using the Name field, we can quickly
see that this first line is for Block 2004, in Block Group 2, in Census Tract 515.03, in
Washington County, Rhode Island. We start off with the data for variables P1_002N
through P1_008N, and end with the unique codes for the state, county, tract, and block.
As you can see, once you get the hang of it, the Census API can provide a very quick and
easy way to get the data you need. I hope this tutorial helps you in finding the 2020 P.L.
94-171 Redistricting Data through the Census API.
We’ve provided some links for guidance below that will be sure to come in handy,
whether you’re a Census API newcomer or a Census API expert. If you’d like more
guidance on how to use the Census API, the data platform data.census.gov, or our
Microdata Access, please visit our resource page linked below. Thank you.