Spring over navigation

US Population by ZIP Code

US Census Population Decennial Zip ZCTA5

Den amerikanske befolkning efter køn og race for hvert postnummer i USA, der stammer fra folketællingen for 2010.

Dette datasæt stammer fra det amerikanske Census Bureaus Decennial Census-datasæt-API’er. Gennemse servicebetingelserne samt politikker og meddelelser for at få oplysninger om betingelser og vilkår for brug af dette datasæt.

Mængde og opbevaring

Dette datasæt er lagret i Parquet-formatet og rummer data fra 2010.

Lagerplacering

Dette datasæt er gemt i Azure-området Det østlige USA. Tildeling af beregningsressourcer i det østlige USA anbefales af tilhørsmæssige årsager.

Relaterede datasæt

Meddelelser

MICROSOFT STILLER AZURE OPEN DATASETS TIL RÅDIGHED, SOM DE ER OG FOREFINDES. MICROSOFT FRASKRIVER SIG ETHVERT ANSVAR, UDTRYKKELIGT ELLER STILTIENDE, OG GARANTIER ELLER BETINGELSER MED HENSYN TIL BRUGEN AF DATASÆTTENE. I DET OMFANG DET ER TILLADT I HENHOLD TIL GÆLDENDE LOVGIVNING FRASKRIVER MICROSOFT SIG ETHVERT ANSVAR FOR SKADER ELLER TAB, INKLUSIVE DIREKTE, FØLGESKADER, SÆRLIGE SKADER, INDIREKTE SKADER, HÆNDELIGE SKADER ELLER PONALE SKADER, DER MÅTTE OPSTÅ I FORBINDELSE MED BRUG AF DATASÆTTENE.

Dette datasæt stilles til rådighed under de oprindelige vilkår, som Microsoft modtog kildedataene under. Datasættet kan indeholde data fra 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.

Azure Synapse

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

Det tidspunkt, hvor den folketælling, der foretages hvert 10. år, fandt sted, f.eks. 2010, 2000.

maxAge int 23 14
20

Maksimum for aldersinterval. Hvis værdien er null, er alle aldre inkluderet, eller også er der ingen øvre grænse for aldersintervallet, f.eks. > 85.

minAge int 23 67
22

Minimum for aldersinterval. Hvis værdien er null, er det på tværs af alle aldre.

population int 29,274 1
2

Befolkningstal for dette segment.

race string 8 NATIVE HAWAIIAN AND OTHER PACIFIC ISLANDER ALONE
WHITE ALONE

Racekategori i Census-data. Hvis værdien er null, er det på tværs af alle racer.

sex string 3 Female
Male

Mand eller kvinde. Hvis værdien er null, er det på tværs af begge køn.

year int 1 2010

År (i heltal) for den tiårige periode.

zipCode string 33,120 12545
08720

5-cifret ZCTA5 (Digit ZIP Code Tabulation Area).

Select your preferred service:

Azure Notebooks

Azure Databricks

Azure Synapse

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
In [1]:
# Pip install packages
import os, sys

!{sys.executable} -m pip install azure-storage-blob
!{sys.executable} -m pip install pyarrow
!{sys.executable} -m pip install pandas
In [2]:
# Azure storage access info
azure_storage_account_name = "azureopendatastorage"
azure_storage_sas_token = r""
container_name = "censusdatacontainer"
folder_name = "release/us_population_zip/"
In [3]:
from azure.storage.blob import BlockBlobServicefrom azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

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 + '"...')
container_url = f"https://{azure_storage_account_name}.blob.core.windows.net/"
blob_service_client = BlobServiceClient(
    container_url, azure_storage_sas_token if azure_storage_sas_token else None)

container_client = blob_service_client.get_container_client(container_name)
blobs = container_client.list_blobs(folder_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)
blob_client = container_client.get_blob_client(targetBlobName)
with open(filename, 'wb') as local_file:
    blob_client.download_blob().download_to_stream(local_file)
In [4]:
# Read the parquet file into Pandas data frame
import pandas as pd

print('Reading the parquet file into Pandas data frame')
df = pd.read_parquet(filename)
In [5]:
# you can add your filter at below
print('Loaded as a Pandas data frame: ')
df
In [6]:
 

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
In [1]:
# Azure storage access info
blob_account_name = "azureopendatastorage"
blob_container_name = "censusdatacontainer"
blob_relative_path = "release/us_population_zip/"
blob_sas_token = r""
In [2]:
# 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)
In [3]:
# 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')
In [4]:
# Display top 10 rows
print('Displaying top 10 rows: ')
display(spark.sql('SELECT * FROM source LIMIT 10'))

Azure Synapse

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

population = UsPopulationZip()
population_df = population.to_spark_dataframe()
In [42]:
# Display top 5 rows
display(population_df.limit(5))
Out[42]:
In [1]:
# Azure storage access info
blob_account_name = "azureopendatastorage"
blob_container_name = "censusdatacontainer"
blob_relative_path = "release/us_population_zip/"
blob_sas_token = r""
In [2]:
# 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)
In [3]:
# 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')
In [4]:
# Display top 10 rows
print('Displaying top 10 rows: ')
display(spark.sql('SELECT * FROM source LIMIT 10'))