Skip Navigation

US Population by ZIP Code

Census Decennial Population US ZCTA5 Zip

US population by gender and race for each US ZIP code sourced from 2010 Decennial Census.

This dataset is sourced from United States Census Bureau’s Decennial Census Dataset APIs. Review Terms of Service and Policies and Notices for the terms and conditions related to the use this dataset.

Volume and Retention

This dataset is stored in Parquet format and has data for the year 2010.

Storage Location

This dataset is stored in the East US Azure region. Allocating compute resources in East US is recommended for affinity.

Notices

MICROSOFT PROVIDES AZURE OPEN DATASETS ON AN “AS IS” BASIS. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, GUARANTEES OR CONDITIONS WITH RESPECT TO YOUR USE OF THE DATASETS. TO THE EXTENT PERMITTED UNDER YOUR LOCAL LAW, MICROSOFT DISCLAIMS ALL LIABILITY FOR ANY DAMAGES OR LOSSES, INCLUDING DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, INCIDENTAL OR PUNITIVE, RESULTING FROM YOUR USE OF THE DATASETS.

This dataset is provided under the original terms that Microsoft received source data. The dataset may include data sourced from Microsoft.

Access

Available inWhen to use
Azure Notebooks

Quickly explore the dataset with Jupyter notebooks hosted on Azure or your local machine.

Azure Databricks

Use this when you need the scale of an Azure managed Spark cluster to process the dataset.

Preview

decennialTime zipCode population race sex minAge maxAge year
2010 77477 265 WHITE ALONE Female 15 17 2010
2010 77477 107 SOME OTHER RACE ALONE Female 15 17 2010
2010 77477 12 SOME OTHER RACE ALONE Female 65 66 2010
2010 77477 101 ASIAN ALONE Female 60 61 2010
2010 77477 221 ASIAN ALONE Male 10 14 2010
2010 77478 256 WHITE ALONE Female 15 17 2010
2010 77478 17 SOME OTHER RACE ALONE Female 15 17 2010
2010 77478 3 SOME OTHER RACE ALONE Female 65 66 2010
2010 77478 129 ASIAN ALONE Female 60 61 2010
2010 77478 296 ASIAN ALONE Male 10 14 2010
Name Data type Unique Values (sample) Description
decennialTime string 1 2010

The time of the decennial census happened, e.g. 2010, 2000.

maxAge int 23 9
19

Max of the age range. If it’s null, it’s across all ages or the age range has no upper bound, e.g. age > 85.

minAge int 23 85
40

Min of the age range. If it’s null, it’s across all ages.

population int 29,274 1
2

Population of this segment.

race string 8 WHITE ALONE
TWO OR MORE RACES

Race category in Census data. If it’s null, it’s across all races.

sex string 3 Male
Female

Male or female. If it’s null, it’s across both sexes.

year int 1 2010

Year (in integer) of the decennial time.

zipCode string 33,120 54169
74129

5-Digit ZIP Code Tabulation Area (ZCTA5).

Select your preferred service:

Azure Notebooks

Azure Databricks

Azure Notebooks

Package: Language: Python Python
In [1]:
# This is a package in preview.
from azureml.opendatasets import UsPopulationZip

population = UsPopulationZip()
population_df = population.to_pandas_dataframe()
ActivityStarted, to_pandas_dataframe
ActivityStarted, to_pandas_dataframe_in_worker
Looking for parquet files...
Reading them into Pandas dataframe...
Reading release/us_population_zip/year=2010/part-00178-tid-5434563040420806442-84b5e4ab-8ab1-4e28-beb1-81caf32ca312-1919656.c000.snappy.parquet under container censusdatacontainer
Done.
ActivityCompleted: Activity=to_pandas_dataframe_in_worker, HowEnded=Success, Duration=34526.07 [ms]
ActivityCompleted: Activity=to_pandas_dataframe, HowEnded=Success, Duration=34538.26 [ms]
In [2]:
population_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 19077120 entries, 0 to 19077119
Data columns (total 7 columns):
decennialTime    object
zipCode          object
population       int32
race             object
sex              object
minAge           float64
maxAge           float64
dtypes: float64(2), int32(1), object(4)
memory usage: 946.1+ MB
# Pip install packages
import os, sys

!{sys.executable} -m pip install azure-storage
!{sys.executable} -m pip install pyarrow
!{sys.executable} -m pip install pandas

# COMMAND ----------

# Azure storage access info
azure_storage_account_name = "azureopendatastorage"
azure_storage_sas_token = r""
container_name = "censusdatacontainer"
folder_name = "release/us_population_zip/"

# COMMAND ----------

from azure.storage.blob import BlockBlobService

if azure_storage_account_name is None or azure_storage_sas_token is None:
    raise Exception("Provide your specific name and key for your Azure Storage account--see the Prerequisites section earlier.")

print('Looking for the first parquet under the folder ' + folder_name + ' in container "' + container_name + '"...')
blob_service = BlockBlobService(account_name = azure_storage_account_name, sas_token = azure_storage_sas_token,)
blobs = blob_service.list_blobs(container_name)
sorted_blobs = sorted(list(blobs), key=lambda e: e.name, reverse=True)
targetBlobName=''
for blob in sorted_blobs:
    if blob.name.startswith(folder_name) and blob.name.endswith('.parquet'):
        targetBlobName = blob.name
        break

print('Target blob to download: ' + targetBlobName)
_, filename = os.path.split(targetBlobName)
parquet_file=blob_service.get_blob_to_path(container_name, targetBlobName, filename)

# COMMAND ----------

# Read the local parquet file into Pandas data frame
import pyarrow.parquet as pq
import pandas as pd

appended_df = []
print('Reading the local parquet file into Pandas data frame')
df = pq.read_table(filename).to_pandas()

# COMMAND ----------

# you can add your filter at below
print('Loaded as a Pandas data frame: ')
df

# COMMAND ----------


Azure Databricks

Package: Language: Python Python
In [1]:
# This is a package in preview.
from azureml.opendatasets import UsPopulationZip

population = UsPopulationZip()
population_df = population.to_spark_dataframe()
ActivityStarted, to_spark_dataframe ActivityStarted, to_spark_dataframe_in_worker ActivityCompleted: Activity=to_spark_dataframe_in_worker, HowEnded=Success, Duration=4108.82 [ms] ActivityCompleted: Activity=to_spark_dataframe, HowEnded=Success, Duration=4111.16 [ms]
In [2]:
display(population_df.limit(5))
decennialTimezipCodepopulationracesexminAgemaxAgeyear
201077477265WHITE ALONEFemale15172010
201077477107SOME OTHER RACE ALONEFemale15172010
20107747712SOME OTHER RACE ALONEFemale65662010
201077477101ASIAN ALONEFemale60612010
201077477221ASIAN ALONEMale10142010
# Databricks notebook source
# Azure storage access info
blob_account_name = "azureopendatastorage"
blob_container_name = "censusdatacontainer"
blob_relative_path = "release/us_population_zip/"
blob_sas_token = r""

# COMMAND ----------

# Allow SPARK to read from Blob remotely
wasbs_path = 'wasbs://%s@%s.blob.core.windows.net/%s' % (blob_container_name, blob_account_name, blob_relative_path)
spark.conf.set(
  'fs.azure.sas.%s.%s.blob.core.windows.net' % (blob_container_name, blob_account_name),
  blob_sas_token)
print('Remote blob path: ' + wasbs_path)

# COMMAND ----------

# SPARK read parquet, note that it won't load any data yet by now
df = spark.read.parquet(wasbs_path)
print('Register the DataFrame as a SQL temporary view: source')
df.createOrReplaceTempView('source')

# COMMAND ----------

# Display top 10 rows
print('Displaying top 10 rows: ')
display(spark.sql('SELECT * FROM source LIMIT 10'))