Part 4 - What to enrich with? (What are Data Collections and Analysis Variables?)

Data Collections and GeoEnrichment coverage

As described earlier, a data collection is a preassembled list of attributes that will be used to enrich the input features. Collection attributes can describe various types of information, such as demographic characteristics and geographic context of the locations or areas submitted as input features.

Some data collections (such as default) can be used in all supported countries. Other data collections may only be available in one or a collection of countries. Data Browser can be used to examine the entire global listing of variables, and associated datasets for each country.

List Countries with GeoEnrichment Data

The get_countries() method can be used to query the countries for which GeoEnrichment data is available, and it returns a list of Country objects with which you can further query for properties. This list can also be viewed here.

from arcgis.gis import GIS
from arcgis.geoenrichment import Country, enrich, get_countries
# Create a GIS Connection
gis = GIS(profile='your_online_profile')
countries = get_countries()
print("Number of countries for which GeoEnrichment data is available: " + str(len(countries)))

#print a few countries for a sample
countries[0:10]
Number of countries for which GeoEnrichment data is available: 177
iso2iso3namealt_namedatasetsdefault_datasetcontinenthierarchy
0ALALBAlbaniaALBANIA[ALB_MBR_2021]ALB_MBR_2021Europe[census]
1DZDZAAlgeriaALGERIA[DZA_MBR_2021]DZA_MBR_2021Africa[census]
2ADANDAndorraANDORRA[AND_MBR_2021]AND_MBR_2021Europe[census]
3AOAGOAngolaANGOLA[AGO_MBR_2021]AGO_MBR_2021Africa[census]
4AIAIAAnguillaANGUILLA[AIA_MBR_2020]AIA_MBR_2020North America[census]
5ARARGArgentinaARGENTINA[ARG_MBR_2020]ARG_MBR_2020South America[census]
6AMARMArmeniaARMENIA[ARM_MBR_2020]ARM_MBR_2020Europe[census]
7AWABWArubaARUBA[ABW_MBR_2020]ABW_MBR_2020North America[census]
8AUAUSAustraliaAUSTRALIA[AUS_ABS_2016, AUS_MBR_2020]AUS_ABS_2016Oceania[AUS_ABS, census]
9ATAUTAustriaAUSTRIA[AUT_MBR_2021]AUT_MBR_2021Europe[census]

Data Collections for U.S.

The data_collections property of a Country object lists its available data collections and analysis variables under each data collection as a Pandas dataframe.

In order to discover the data collections for a particular country, you may first access the reference variable to it using the country.get() method, and then fetch the data collections from country.data_collections property. Once we know the data collection we would like to use, we can look at analysisVariables available in that data collection.

# Get US as a country
usa = Country.get('US')
type(usa)
arcgis.geoenrichment.enrichment.Country
usa_df = usa.data_collections

# print a few rows of the DataFrame
usa_df.head()
analysisVariablealiasfieldCategoryvintage
dataCollectionID
1yearincrements1yearincrements.AGE0_CY2022 Population Age <12022 Age: 1 Year Increments (Esri)2022
1yearincrements1yearincrements.AGE1_CY2022 Population Age 12022 Age: 1 Year Increments (Esri)2022
1yearincrements1yearincrements.AGE2_CY2022 Population Age 22022 Age: 1 Year Increments (Esri)2022
1yearincrements1yearincrements.AGE3_CY2022 Population Age 32022 Age: 1 Year Increments (Esri)2022
1yearincrements1yearincrements.AGE4_CY2022 Population Age 42022 Age: 1 Year Increments (Esri)2022
usa_df.shape
(18946, 4)

Unique Data Collections for U.S.

Each data collection and analysis variable has a unique ID. When calling the enrich() method (explained earlier in this guide) these analysis variables can be passed in the data_collections and analysis_variables parameters.

As an example, here we see a subset of the data collections for US showing 2 different data collections and multiple analysis variables for each collection.

usa_df.iloc[500:600,:]
analysisVariablealiasfieldCategoryvintage
dataCollectionID
1yearincrements1yearincrements.FAGE75_FY2027 Females Age 752027 Age: 1 Year Increments (Esri)2027
1yearincrements1yearincrements.FAGE76_FY2027 Females Age 762027 Age: 1 Year Increments (Esri)2027
1yearincrements1yearincrements.FAGE77_FY2027 Females Age 772027 Age: 1 Year Increments (Esri)2027
1yearincrements1yearincrements.FAGE78_FY2027 Females Age 782027 Age: 1 Year Increments (Esri)2027
1yearincrements1yearincrements.FAGE79_FY2027 Females Age 792027 Age: 1 Year Increments (Esri)2027
...............
5yearincrements5yearincrements.MEDAGE_CY2022 Median Age2022 Age: 5 Year Increments (Esri)2022
5yearincrements5yearincrements.MALES_CY2022 Male Population2022 Age: 5 Year Increments (Esri)2022
5yearincrements5yearincrements.MALE0_CY2022 Males Age 0-42022 Age: 5 Year Increments (Esri)2022
5yearincrements5yearincrements.MALE5_CY2022 Males Age 5-92022 Age: 5 Year Increments (Esri)2022
5yearincrements5yearincrements.MALE10_CY2022 Males Age 10-142022 Age: 5 Year Increments (Esri)2022

100 rows × 4 columns

The table above shows 2 different data collections (1yearincrements and 5yearincrements). Since these are Age data collections, the analysisVariables for these collections are similar. vintage shows the year that the demographic data represents. For example, a vintage of 2020 means that the data represents the year 2020.

Let's get a list of unique data collections that are available for U.S.

usa_df.index.nunique()
115

United States has 150 unique data collections. Here are the first 10 data collections.

list(usa_df.index.unique())[:10]
['1yearincrements',
 '5yearincrements',
 'Age',
 'agebyracebysex',
 'AgeDependency',
 'AtRisk',
 'AutomobilesAutomotiveProducts',
 'BabyProductsToysGames',
 'basicFactsForMobileApps',
 'businesses']

Looking at fieldCategory is a great way to clearly understand what the data collection is about. fieldCategory combines vintage, datacollectionID columns along with the year and data collection. However, to query a data collection its unique ID (dataCollectionID) must be used.

Let's look at the fieldCategory column for a few data collections in US.

usa_df.fieldCategory.unique()[:10]
array(['2022 Age: 1 Year Increments (Esri)',
       '2027 Age: 1 Year Increments (Esri)',
       '2010 Age: 1 Year Increments (U.S. Census)',
       '2022 Age: 5 Year Increments (Esri)',
       '2027 Age: 5 Year Increments (Esri)',
       '2010 Age: 5 Year Increments (U.S. Census)',
       '2016-2020 Age: 5 Year Increments (ACS)',
       '2022 Age by Sex by Race (Esri)', '2027 Age by Sex by Race (Esri)',
       '2010 Age by Sex by Race (U.S. Census)'], dtype=object)

Data Collections by Socio-demographic Factors

You can filter the data_collections to get collections for a specific factor using Pandas expressions. Let's loook at data collections for different socio-demographic factors such as Age, Population, Income.

Data Collections for Age

Age_Collections = usa_df['fieldCategory'].str.contains('Age', na=False)
usa_df[Age_Collections].fieldCategory.unique()
array(['2022 Age: 1 Year Increments (Esri)',
       '2027 Age: 1 Year Increments (Esri)',
       '2010 Age: 1 Year Increments (U.S. Census)',
       '2022 Age: 5 Year Increments (Esri)',
       '2027 Age: 5 Year Increments (Esri)',
       '2010 Age: 5 Year Increments (U.S. Census)',
       '2016-2020 Age: 5 Year Increments (ACS)',
       '2022 Age by Sex by Race (Esri)', '2027 Age by Sex by Race (Esri)',
       '2010 Age by Sex by Race (U.S. Census)',
       '2022 Age Dependency (Esri)', '2027 Age Dependency (Esri)',
       '2022 Disposable Income by Age (Esri)',
       '2010 Households by Age of Householder (U.S. Census)',
       '2016-2020 Households by Type and Size and Age (ACS)',
       '2010 Housing by Age of Householder (U.S. Census)',
       '2022 Income by Age (Esri)', '2027 Income by Age (Esri)',
       '2016-2020 Income by Age (ACS)', 'Age: 5 Year Increments',
       '2022 Net Worth by Age (Esri)',
       '2016-2020 Females by Age of Children and Employment Status (ACS)'],
      dtype=object)

Data Collections for Population

Pop_Collections = usa_df['fieldCategory'].str.contains('Population', na=False)
usa_df[Pop_Collections].fieldCategory.unique()
array(['2010 Population (U.S. Census)',
       '2016-2020 Population by Language Spoken at Home (ACS)',
       '2022 Daytime Population (Esri)',
       '2022 Population by Generation (Esri)',
       '2027 Population by Generation (Esri)',
       '2020 Group Quarters Population (U.S. Census)',
       '2020 Group Quarters Population by Type (U.S. Census)',
       '2010 Group Quarters Population (U.S. Census)',
       '2020 Hispanic Population by Race (U.S. Census)',
       '2020 Hispanic Population of Two or More Races (U.S. Census)',
       '2020 Hispanic Population <18 Years by Race (U.S. Census)',
       '2020 Hispanic Population 18+ Years by Race (U.S. Census)',
       '2020 Hispanic Population 18+ Years of Two or More Races (U.S. Census)',
       '2022 Population Time Series (Esri)',
       '2010 Population by Relationship and Household Type (U.S. Census)',
       '2016-2020 Population by Relationship and Household Type (ACS)',
       '2020 Non Hispanic Population by Race (U.S. Census)',
       '2020 Non Hispanic Population of Two or More Races (U.S. Census)',
       '2020 Non Hispanic Population <18 Years by Race (U.S. Census)',
       '2020 Non Hispanic Population 18+ Years by Race (U.S. Census)',
       '2020 Non Hispanic Population 18+ Years of Two or More Races (U.S. Census)',
       '2022 Population (Esri)', '2020 Population (U.S. Census)',
       '2020 Population by Race (U.S. Census)',
       '2020 Population of Two or More Races (U.S. Census)',
       '2020 Population <18 Years by Race (U.S. Census)',
       '2020 Population 18+ Years by Race (U.S. Census)',
       '2020 Population 18+ Years of Two or More Races (U.S. Census)'],
      dtype=object)

Data Collections for Income

Income_Collections = usa_df['fieldCategory'].str.contains('Income', na=False)
Income_Collections.index.unique()
Index(['1yearincrements', '5yearincrements', 'Age', 'agebyracebysex',
       'AgeDependency', 'AtRisk', 'AutomobilesAutomotiveProducts',
       'BabyProductsToysGames', 'basicFactsForMobileApps', 'businesses',
       ...
       'travelMPI', 'unitsinstructure', 'urbanizationgroupsNEW', 'vacant',
       'vehiclesavailable', 'veterans', 'Wealth', 'women', 'yearbuilt',
       'yearmovedin'],
      dtype='object', name='dataCollectionID', length=115)

As mentioned earlier, using a data_collection's unique ID (dataCollectionID) is the best way to further query a data collection. Let's look at the dataCollectionID for various Income data collections.

usa_df[Income_Collections].index.unique()
Index(['AtRisk', 'basicFactsForMobileApps', 'disposableincome',
       'foodstampsSNAP', 'Health', 'householdincome', 'households',
       'incomebyage', 'KeyUSFacts', 'Policy', 'population', 'Wealth'],
      dtype='object', name='dataCollectionID')

Analysis variables for Data Collections

Once we know the data collection we would like to use, we can look at all the unique variables available in that data collection using its unique ID. Let's discover analysisVariables for some of the data collections.

Analysis variables for Age data collection

usa_df.loc['Age']['analysisVariable'].unique()
array(['Age.MALE0', 'Age.MALE5', 'Age.MALE10', 'Age.MALE15', 'Age.MALE20',
       'Age.MALE25', 'Age.MALE30', 'Age.MALE35', 'Age.MALE40',
       'Age.MALE45', 'Age.MALE50', 'Age.MALE55', 'Age.MALE60',
       'Age.MALE65', 'Age.MALE70', 'Age.MALE75', 'Age.MALE80',
       'Age.MALE85', 'Age.FEM0', 'Age.FEM5', 'Age.FEM10', 'Age.FEM15',
       'Age.FEM20', 'Age.FEM25', 'Age.FEM30', 'Age.FEM35', 'Age.FEM40',
       'Age.FEM45', 'Age.FEM50', 'Age.FEM55', 'Age.FEM60', 'Age.FEM65',
       'Age.FEM70', 'Age.FEM75', 'Age.FEM80', 'Age.FEM85'], dtype=object)

Analysis variables are typically represented as dataCollectionID.<analysis variable name> as seen above.

Analysis variables for DaytimePopulation data collection

usa_df.loc['DaytimePopulation']['analysisVariable'].unique()
array(['DaytimePopulation.DPOP_CY', 'DaytimePopulation.DPOPWRK_CY',
       'DaytimePopulation.DPOPRES_CY', 'DaytimePopulation.DPOPDENSCY'],
      dtype=object)

Data Collections for Another Country

Let's look at data collections for New Zealand. Data Browser can be used to examine the entire global listing of variables, and associated datasets for New Zealand.

In order to discover the data collections for a particular country, you may first access the reference variable to it using the country.get() method, and then fetch the data collections from country.data_collections property. Once we know the data collection we would like to use, we can look at analysisVariables available in that data collection.

# Get US as a country
nz = Country.get('New Zealand')
type(nz)
arcgis.geoenrichment.enrichment.Country
nz_df = nz.data_collections

# print a few rows of the DataFrame
nz_df.head()
analysisVariablealiasfieldCategoryvintage
dataCollectionID
15YearIncrements15YearIncrements.PAGE01_CY2020 Total Population Age 0-142020 Population Totals (MBR)2020
15YearIncrements15YearIncrements.PAGE02_CY2020 Total Population Age 15-292020 Population Totals (MBR)2020
15YearIncrements15YearIncrements.PAGE03_CY2020 Total Population Age 30-442020 Population Totals (MBR)2020
15YearIncrements15YearIncrements.PAGE04_CY2020 Total Population Age 45-592020 Population Totals (MBR)2020
15YearIncrements15YearIncrements.PAGE05_CY2020 Total Population Age 60+2020 Population Totals (MBR)2020
nz_df.shape
(193, 4)

Unique Data Collections for New Zealand

Let's get a list of unique data collections that are available for New Zealand.

nz_df.index.unique()
Index(['15YearIncrements', 'EducationalAttainment', 'Gender',
       'HouseholdsbyIncome', 'HouseholdsbyType', 'HouseholdTotals', 'KeyFacts',
       'KeyGlobalFacts', 'MaritalStatus', 'PopulationTotals',
       'PurchasingPower', 'Spending'],
      dtype='object', name='dataCollectionID')

New Zealand has 12 unique data collections.

We can look at the fieldCategory column to understand each category better.

nz_df.fieldCategory.unique()
array(['2020 Population Totals (MBR)',
       '2020 Male Population Totals (MBR)',
       '2020 Female Population Totals (MBR)',
       '2020 Educational Attainment (MBR)',
       '2020 Households by Income (MBR)', '2020 Households by Type (MBR)',
       '2020 Household Totals (MBR)', '2020 Marital Status (MBR)',
       '2020 Purchasing Power (MBR)', 'Key Demographic Indicators',
       'Age: 5 Year Increments',
       '2020 Food & Beverage Expenditures (MBR)',
       '2020 Alcoholic Beverage Expenditures (MBR)',
       '2020 Tobacco Expenditures (MBR)',
       '2020 Clothing Expenditures (MBR)',
       '2020 Footwear Expenditures (MBR)',
       '2020 Furniture & Furnishing Expenditures (MBR)',
       '2020 Household Textiles Expenditures (MBR)',
       '2020 Household Appliances Expenditures (MBR)',
       '2020 Household Utensils Expenditures (MBR)',
       '2020 House & Garden Expenditures (MBR)',
       '2020 Household Maintenance Expenditures (MBR)',
       '2020 Medical Products & Supplies Expenditures (MBR)',
       '2020 Consumer Electronics Expenditures (MBR)',
       '2020 Recreation & Culture Durable Expenditures (MBR)',
       '2020 Entertainment Expenditures (MBR)',
       '2020 Recreational & Cultural Service Expenditures (MBR)',
       '2020 Books & Stationery Expenditures (MBR)',
       '2020 Catering Services Expenditures (MBR)',
       '2020 Personal Care Expenditures (MBR)',
       '2020 Jewelry & Personal Effects Expenditures (MBR)'], dtype=object)

Looking at fieldCategory is a great way to clearly understand what the data collection is about. However, to query a data collection its unique ID (dataCollectionID) must be used.

Data Collections for Socio-demographic Factors

New Zealand has fewer data_collections compared to U.S. Let's look at data collections for Key Facts, Education and Spending.

Data Collection for Key Facts

nz_df.loc['KeyGlobalFacts']
analysisVariablealiasfieldCategoryvintage
dataCollectionID
KeyGlobalFactsKeyGlobalFacts.TOTPOPTotal PopulationKey Demographic IndicatorsNaN
KeyGlobalFactsKeyGlobalFacts.TOTHHTotal HouseholdsKey Demographic IndicatorsNaN
KeyGlobalFactsKeyGlobalFacts.AVGHHSZAverage Household SizeKey Demographic IndicatorsNaN
KeyGlobalFactsKeyGlobalFacts.TOTMALESMale PopulationAge: 5 Year IncrementsNaN
KeyGlobalFactsKeyGlobalFacts.TOTFEMALESFemale PopulationAge: 5 Year IncrementsNaN

Data Collection for Education

nz_df.loc['EducationalAttainment']
analysisVariablealiasfieldCategoryvintage
dataCollectionID
EducationalAttainmentEducationalAttainment.EDUC01A_CY2020 Pop 15+/Edu: No Qualification2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC02A_CY2020 Pop 15+/Edu: Level 12020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC03A_CY2020 Pop 15+/Edu: Level 22020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC04A_CY2020 Pop 15+/Edu: Level 32020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC05A_CY2020 Pop 15+/Edu: Level 42020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC06B_CY2020 Pop 15+/Edu: Level 5 Diploma2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC07A_CY2020 Pop 15+/Edu: Level 6 Diploma2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC08A_CY2020 Pop 15+/Edu: Bachelor Degree2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC09A_CY2020 Pop 15+/Edu: Post-graduate and Honours de...2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC10A_CY2020 Pop 15+/Edu: Master's Degree2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC11A_CY2020 Pop 15+/Edu: Doctorate2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC12A_CY2020 Pop 15+/Edu: Overseas Secondary School2020 Educational Attainment (MBR)2020
EducationalAttainmentEducationalAttainment.EDUC13_CY2020 Pop 15+/Edu: Not Included Elsewhere2020 Educational Attainment (MBR)2020

Data Collection for Spending

nz_df.loc['Spending']
analysisVariablealiasfieldCategoryvintage
dataCollectionID
SpendingSpending.CS01_CY2020 Food & Beverage: Total2020 Food & Beverage Expenditures (MBR)2020
SpendingSpending.CS01PRM_CY2020 Food & Beverage: Per Mill2020 Food & Beverage Expenditures (MBR)2020
SpendingSpending.CSPC01_CY2020 Food & Beverage: Per Capita2020 Food & Beverage Expenditures (MBR)2020
SpendingSpending.CS01IDX_CY2020 Food & Beverage: Index2020 Food & Beverage Expenditures (MBR)2020
SpendingSpending.CS02_CY2020 Alcoholic Beverage: Total2020 Alcoholic Beverage Expenditures (MBR)2020
...............
SpendingSpending.CS19IDX_CY2020 Personal Care: Index2020 Personal Care Expenditures (MBR)2020
SpendingSpending.CS20_CY2020 Personal Effects: Total2020 Jewelry & Personal Effects Expenditures (...2020
SpendingSpending.CS20PRM_CY2020 Personal Effects: Per Mill2020 Jewelry & Personal Effects Expenditures (...2020
SpendingSpending.CSPC20_CY2020 Personal Effects: Per Capita2020 Jewelry & Personal Effects Expenditures (...2020
SpendingSpending.CS20IDX_CY2020 Personal Effects: Index2020 Jewelry & Personal Effects Expenditures (...2020

80 rows × 4 columns

Analysis variables for Data Collections

Once we know the data collection we would like to use, we can look at all the unique variables available in that data collection using its unique ID. Let's discover analysisVariables for some of the data collections we looked at earlier.

Analysis variables for KeyGlobalFacts data collection

nz_df.loc['KeyGlobalFacts']['analysisVariable'].unique()
array(['KeyGlobalFacts.TOTPOP', 'KeyGlobalFacts.TOTHH',
       'KeyGlobalFacts.AVGHHSZ', 'KeyGlobalFacts.TOTMALES',
       'KeyGlobalFacts.TOTFEMALES'], dtype=object)

Analysis variables for EducationalAttainment data collection

nz_df.loc['EducationalAttainment']['analysisVariable'].unique()
array(['EducationalAttainment.EDUC01A_CY',
       'EducationalAttainment.EDUC02A_CY',
       'EducationalAttainment.EDUC03A_CY',
       'EducationalAttainment.EDUC04A_CY',
       'EducationalAttainment.EDUC05A_CY',
       'EducationalAttainment.EDUC06B_CY',
       'EducationalAttainment.EDUC07A_CY',
       'EducationalAttainment.EDUC08A_CY',
       'EducationalAttainment.EDUC09A_CY',
       'EducationalAttainment.EDUC10A_CY',
       'EducationalAttainment.EDUC11A_CY',
       'EducationalAttainment.EDUC12A_CY',
       'EducationalAttainment.EDUC13_CY'], dtype=object)

Analysis variables for Spending data collection

nz_df.loc['Spending']['analysisVariable'].unique()
array(['Spending.CS01_CY', 'Spending.CS01PRM_CY', 'Spending.CSPC01_CY',
       'Spending.CS01IDX_CY', 'Spending.CS02_CY', 'Spending.CS02PRM_CY',
       'Spending.CSPC02_CY', 'Spending.CS02IDX_CY', 'Spending.CS03_CY',
       'Spending.CS03PRM_CY', 'Spending.CSPC03_CY', 'Spending.CS03IDX_CY',
       'Spending.CS04_CY', 'Spending.CS04PRM_CY', 'Spending.CSPC04_CY',
       'Spending.CS04IDX_CY', 'Spending.CS05_CY', 'Spending.CS05PRM_CY',
       'Spending.CSPC05_CY', 'Spending.CS05IDX_CY', 'Spending.CS06_CY',
       'Spending.CS06PRM_CY', 'Spending.CSPC06_CY', 'Spending.CS06IDX_CY',
       'Spending.CS07_CY', 'Spending.CS07PRM_CY', 'Spending.CSPC07_CY',
       'Spending.CS07IDX_CY', 'Spending.CS08_CY', 'Spending.CS08PRM_CY',
       'Spending.CSPC08_CY', 'Spending.CS08IDX_CY', 'Spending.CS09_CY',
       'Spending.CS09PRM_CY', 'Spending.CSPC09_CY', 'Spending.CS09IDX_CY',
       'Spending.CS10_CY', 'Spending.CS10PRM_CY', 'Spending.CSPC10_CY',
       'Spending.CS10IDX_CY', 'Spending.CS11_CY', 'Spending.CS11PRM_CY',
       'Spending.CSPC11_CY', 'Spending.CS11IDX_CY', 'Spending.CS12_CY',
       'Spending.CS12PRM_CY', 'Spending.CSPC12_CY', 'Spending.CS12IDX_CY',
       'Spending.CS13_CY', 'Spending.CS13PRM_CY', 'Spending.CSPC13_CY',
       'Spending.CS13IDX_CY', 'Spending.CS14_CY', 'Spending.CS14PRM_CY',
       'Spending.CSPC14_CY', 'Spending.CS14IDX_CY', 'Spending.CS15_CY',
       'Spending.CS15PRM_CY', 'Spending.CSPC15_CY', 'Spending.CS15IDX_CY',
       'Spending.CS16_CY', 'Spending.CS16PRM_CY', 'Spending.CSPC16_CY',
       'Spending.CS16IDX_CY', 'Spending.CS17_CY', 'Spending.CS17PRM_CY',
       'Spending.CSPC17_CY', 'Spending.CS17IDX_CY', 'Spending.CS18_CY',
       'Spending.CS18PRM_CY', 'Spending.CSPC18_CY', 'Spending.CS18IDX_CY',
       'Spending.CS19_CY', 'Spending.CS19PRM_CY', 'Spending.CSPC19_CY',
       'Spending.CS19IDX_CY', 'Spending.CS20_CY', 'Spending.CS20PRM_CY',
       'Spending.CSPC20_CY', 'Spending.CS20IDX_CY'], dtype=object)

Perform Enrichment using Data Collections and Analysis Variables

Data Collections can be used to enrich various study areas. data_collections and analysis_variables can be passed in the enrich() method. Details about enriching study areas can be found in Enriching Study Areas section.

Let's look at a few similar examples of GeoEnrichment here.

Enrich using Data Collections

Enrich with Age data collection

Here we see an address being enriched by data from Age data collection.

# Enriching single address as single line imput
age_coll = enrich(study_areas=["380 New York St Redlands CA 92373"], 
                       data_collections=['Age'])
age_coll
source_countryxyarea_typebuffer_unitsbuffer_units_aliasbuffer_radiiaggregation_methodpopulation_to_polygon_size_ratingapportionment_confidence...fem45fem50fem55fem60fem65fem70fem75fem80fem85SHAPE
0USA-117.1947934.057265RingBufferesriMilesMiles1.0BlockApportionment:US.BlockGroups;PointsLayer:...2.1912.576...366.0392.0365.0345.0322.0277.0168.0103.0132.0{"rings": [[[-117.19479001927878, 34.071773611...

1 rows × 48 columns

age_coll.columns
Index(['source_country', 'x', 'y', 'area_type', 'buffer_units',
       'buffer_units_alias', 'buffer_radii', 'aggregation_method',
       'population_to_polygon_size_rating', 'apportionment_confidence',
       'has_data', 'male0', 'male5', 'male10', 'male15', 'male20', 'male25',
       'male30', 'male35', 'male40', 'male45', 'male50', 'male55', 'male60',
       'male65', 'male70', 'male75', 'male80', 'male85', 'fem0', 'fem5',
       'fem10', 'fem15', 'fem20', 'fem25', 'fem30', 'fem35', 'fem40', 'fem45',
       'fem50', 'fem55', 'fem60', 'fem65', 'fem70', 'fem75', 'fem80', 'fem85',
       'SHAPE'],
      dtype='object')

When a data collection is specified without specific analysis variables, all variables under the data collection are used for enrichment as can be seen above.

Enrich with Health data collection

Here we see a zip code being enriched by data from Health data collection.

redlands = usa.subgeographies.states['California'].zip5['92373']
redlands_df = enrich(study_areas=[redlands], data_collections=['Health'] )
redlands_df
std_geography_levelstd_geography_namestd_geography_idsource_countryaggregation_methodpopulation_to_polygon_size_ratingapportionment_confidencehas_datarel65_hi2_ocacscivnins...pop85_cypop18up_cypop21up_cymedage_cyhhu18_c10medhinc_cys27_buss27_saless27_empSHAPE
0US.ZIP5Redlands92373USAQuery:US.ZIP52.1912.57612.031157.0...1205.028208.027076.042.23851.091009.0224.0306371.04093.0{"rings": [[[-117.16767396036383, 33.976847519...

1 rows × 431 columns

redlands_df.columns
Index(['std_geography_level', 'std_geography_name', 'std_geography_id',
       'source_country', 'aggregation_method',
       'population_to_polygon_size_rating', 'apportionment_confidence',
       'has_data', 'rel65_hi2_oc', 'acscivnins',
       ...
       'pop85_cy', 'pop18up_cy', 'pop21up_cy', 'medage_cy', 'hhu18_c10',
       'medhinc_cy', 's27_bus', 's27_sales', 's27_emp', 'SHAPE'],
      dtype='object', length=431)

Enrich using Analysis Variables

Data can be enriched by specifying specific analysis variables of a data collection with which we want to enrich our data. In this example, we will look at analysis_variables for Age data_collection and then use specific analysis variables to enrich() a study area.

# Unique analysis variables for Age data collection
usa = Country.get('US')
usa.data_collections.loc['Age']['analysisVariable'].unique()
array(['Age.MALE0', 'Age.MALE5', 'Age.MALE10', 'Age.MALE15', 'Age.MALE20',
       'Age.MALE25', 'Age.MALE30', 'Age.MALE35', 'Age.MALE40',
       'Age.MALE45', 'Age.MALE50', 'Age.MALE55', 'Age.MALE60',
       'Age.MALE65', 'Age.MALE70', 'Age.MALE75', 'Age.MALE80',
       'Age.MALE85', 'Age.FEM0', 'Age.FEM5', 'Age.FEM10', 'Age.FEM15',
       'Age.FEM20', 'Age.FEM25', 'Age.FEM30', 'Age.FEM35', 'Age.FEM40',
       'Age.FEM45', 'Age.FEM50', 'Age.FEM55', 'Age.FEM60', 'Age.FEM65',
       'Age.FEM70', 'Age.FEM75', 'Age.FEM80', 'Age.FEM85'], dtype=object)

Now, we will enrich our study area with Age.FEM45, Age.FEM55, Age.FEM65 variables

enrich(study_areas=["380 New York St Redlands CA 92373"], 
       analysis_variables=["Age.FEM45","Age.FEM55","Age.FEM65"])
source_countryxyarea_typebuffer_unitsbuffer_units_aliasbuffer_radiiaggregation_methodpopulation_to_polygon_size_ratingapportionment_confidencehas_datafem45fem55fem65SHAPE
0USA-117.1947934.057265RingBufferesriMilesMiles1.0BlockApportionment:US.BlockGroups;PointsLayer:...2.1912.5761366.0365.0322.0{"rings": [[[-117.19479001927878, 34.071773611...

Enriching Spatially Enabled Dataframes

One of the most common use case for GeoEnrichment is enriching existing data in feature layers. As a user, you may need to analyze and enrich your data that already exists in feature layers. Spatially Enabled DataFrame (SeDF) helps us bring the data from layer into a dataframe which can then be GeoEnriched.

Let's look at an example using an existing layer of Covid-19 dataset. This feature layer includes latest Covid-19 Cases, Recovered and Deaths data for U.S. at the county level.

# Get the layer
gis = GIS(set_active=False)
covid_item = gis.content.get('628578697fb24d8ea4c32fa0c5ae1843')
print(covid_item)
covid_layer = covid_item.layers[0]
covid_layer
<Item title:"COVID-19 Cases US" type:Feature Layer Collection owner:CSSE_covid19>
<FeatureLayer url:"https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases_US/FeatureServer/0">

We can query the layer as a dataframe and then use the dataframe for enrichment.

covid_df = covid_layer.query(as_df=True)
covid_df.shape
(3272, 19)
covid_df.head()
OBJECTIDProvince_StateCountry_RegionLast_UpdateLatLong_ConfirmedRecoveredDeathsActiveAdmin2FIPSCombined_KeyIncident_RatePeople_TestedPeople_HospitalizedUIDISO3SHAPE
01AlabamaUS2022-10-27 17:22:3432.539527-86.64408218511<NA>228<NA>Autauga01001Autauga, Alabama, US33132.864379<NA><NA>84001001USA{"x": -86.64408226999996, "y": 32.539527450000...
12AlabamaUS2022-10-27 17:22:3430.72775-87.72207165973<NA>716<NA>Baldwin01003Baldwin, Alabama, US29553.293853<NA><NA>84001003USA{"x": -87.72207057999998, "y": 30.727749910000...
23AlabamaUS2022-10-27 17:22:3431.868263-85.3871296930<NA>103<NA>Barbour01005Barbour, Alabama, US28072.591752<NA><NA>84001005USA{"x": -85.38712859999998, "y": 31.868263000000...
34AlabamaUS2022-10-27 17:22:3432.996421-87.1251157575<NA>108<NA>Bibb01007Bibb, Alabama, US33826.024828<NA><NA>84001007USA{"x": -87.12511459999996, "y": 32.996420640000...
45AlabamaUS2022-10-27 17:22:3433.982109-86.56790617320<NA>258<NA>Blount01009Blount, Alabama, US29951.92474<NA><NA>84001009USA{"x": -86.56790592999994, "y": 33.982109180000...

To showcase GeoEnrichment, we will create a subset of the original data and then enrich() the subset.

# Create subset
test_df = covid_df.iloc[:100].copy()
test_df.shape
(100, 19)
# Check geometry
test_df.spatial.geometry_type
['point', None]

A dataframe can be passed as a value to study_areas parameter of the enrich() method. Here we are enriching our dataframe with specific variables from Age data collection.

# Enrich dataframe
new_df = enrich(study_areas=test_df.spatial, 
       analysis_variables=["Age.FEM45","Age.FEM55","Age.FEM65"])
new_df.head()
IDOBJECTID_0sourceCountryLong_RecoveredCountry_RegionFIPSLast_UpdateCombined_KeyISO3...bufferUnitsAliasbufferRadiiaggregationMethodpopulationToPolygonSizeRatingapportionmentConfidenceHasDataFEM45FEM55FEM65SHAPE
001US-82.4617070US450011596857725000Abbeville, South Carolina, USUSA...Miles1BlockApportionment:US.BlockGroups2.1912.5761222{"rings": [[[-82.46170657999994, 34.2378420028...
112US-92.4141970US220011596857725000Acadia, Louisiana, USUSA...Miles1BlockApportionment:US.BlockGroups2.1912.5761332{"rings": [[[-92.41419697999997, 30.3095821536...
223US-75.6323460US510011596857725000Accomack, Virginia, USUSA...Miles1BlockApportionment:US.BlockGroups2.1912.5761141614{"rings": [[[-75.63234615, 37.781571251121655]...
334US-116.2415520US160011596857725000Ada, Idaho, USUSA...Miles1BlockApportionment:US.BlockGroups2.1912.5761000{"rings": [[[-116.24155159999998, 43.467142851...
445US-94.4710590US190011596857725000Adair, Iowa, USUSA...Miles1BlockApportionment:US.BlockGroups2.1912.5761111{"rings": [[[-94.47105873999998, 41.3452468224...

5 rows × 31 columns

new_df.drop(['OBJECTID_0', 'ID','Last_Update'], axis=1, inplace=True)
# Check shape
new_df.shape
(91, 28)

We can see that enrichment resulted in 91 records and 31 columns. There are some areas in our dataframe for which enrichment information is not available. Hence, we have 91 records instead of 100. Geoenrichment adds some additional columns along with the analysis variables we enriched for and so we see 31 columns however we are dropping duplicates and unnecessary columns to bring the count down to 28 columns.

Visualize on a Map

Let's visualize the enriched dataframe on a map. We will use FEM65 column to classify our data for plotting on the map.

covid_map = gis.map('USA', 4)
covid_map
# Plot on a map
covid_map.remove_layers()
new_df.spatial.plot(map_widget=covid_map,
                    renderer_type='c',  # for class breaks renderer,
                    method='esriClassifyNaturalBreaks',  # classification algorithm,
                    class_count=5,  # choose the number of classes,
                    col='FEM65',  # numeric column to classify,
                    cmap='viridis',  # color map to pick colors from for each class,
                    alpha=0.7)
True

Conclusion

In this part of the arcgis.geoenrichment module guide series, you saw how data_collections property of a Country object lists its available data_collections and analysis_variables. You explored different data collections, their analysis variables and then enriched study areas using the same. Towards the end, you experienced how spatially enabled dataframes can be enriched.

In the subsequent pages, you will learn about Generating Reports and Standard Geography Queries.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.