Getting Census Data in 5 Easy Steps

Here is a quick 5 step guide to getting it for yourself.


Request a Secret Key from the United States Census BureauIn order to make API calls (just a fancy name for a web request asking for specific data), you will need to request a secret key from the US Census Bureau.

Navigate to the census developers page and you should see “Request a Key”.

You’ll be redirected to a page asking for your organization name (I just put my name) and your email address.

Shortly, you will get an email with a really long string of letters and numbers which is your API Key.

Very important: Keep this key a secret.

Otherwise, others can make requests for data under your name and you don’t necessarily want that.


Find the Right Data SetThe Census Bureau hosts several data sets, some which might be right for your project and some which won’t be.

As an example, on one end of the spectrum we have the American Community (ACS) Survey 1-Year Data which happens every year but only for areas with populations of 65,000+.

On the other end of the spectrum, we have what most people think of as “the census”, officially called the Decennial Census which happens only every 10 years but includes very detailed geographies.

And, there are several levels in between.

You can find a full list here.

For the rest of this post, let’s use a concrete example and suppose we are trying to find a recent population count for zip code 90807 in beautiful Long Beach, California.

For this purpose, we will use ACS 5-Year Data which includes summarized data regarding small geographies for increased statistical reliability as opposed to 1-Year metrics (perfect for the zip code metric we are after).

We’ll use the most recent data set possible, which is from 2017.

Navigating to the web page for ACS 5-Year Data, we see that our API call will start with :https://api.



Find the Right VariablesOk, so we have the right data set.

Now, we need to think about which variables we want from that data set.

You can get pretty general or pretty specific with your variables.

Some examples of variables include:Total populationTotal number of people reporting Canadian ancestryTotal number of grandchildren under the age of 18 living with a grandparent householderAnd … that’s just scratching the surface.

A full list of variables for ACS 5-Year Estimates can be found here.

For us, we’ll keep it basic and go with Total Population.

We can navigate to the variables web page, Ctrl-F for “Total Population” and get the variable name which is B01003_001E.

Cool!.So our API call so far looks like:https://api.


gov/data/2017/acs/acs5?key=[YOUR_API_KEY]&get=B01003_001Ewhich says “From the ACS 5-Year data, I want total population”.


Find the Right GeographiesThe last step is to ask the “where” question.

So far, we have asked for total population from ACS 5-Year data, but haven’t specified that we want this value for zip code 90807.

Achieving that result is as simple as modifying the API call a bit:https://api.


gov/data/2017/acs/acs5?key=[YOUR_API_KEY]&get=B01003_001E&for=zip%20code%20tabulation%20area:90807In case you were wondering, the “%20” is just code for a blank space, since we aren’t allowed to put actual blank spaces in a URL.

As another note, you aren’t limited to just zip codes as your geographies.

You can instead use states, counties, etc.

You would just need to modify the API call accordingly.

I’ve found the best way to figure out the right API call is to look at some examples provided by the Census Bureau and then modify them to suit your needs.


Make the API CallAll the hard work is done!Let’s copy/paste the API call into our browser and see what we get.

Which tells us that the total population in zip code 90807 was 32395 in 2017.

Pretty cool!(6.

) Optional: Store the Results in a SpreadsheetYou’ll probably want to store your results somewhere and this step will walk you through an example of how to do that using python.

The following script will generate a CSV spreadsheet with populations of all zip codes within LA County using a txt file (found at my GitHub here) containing a list of these zip codes.

Thanks for reading and I hope this post made it a bit easier to collect your own census data!.

. More details

Leave a Reply