Enrichment Subscription Workflow

This example illustrates how to subscribe and enrich with CARTO's Data Observatory.

Note: You'll need CARTO Account credentials to reproduce this example.


In [1]:
from cartoframes.auth import set_default_credentials

set_default_credentials('creds.json')

In [2]:
dataset_name = 'carto-do.ags.demographics_retailpotential_usa_blockgroup_2015_yearly_2019'

In [3]:
from cartoframes.data.observatory import Catalog, Dataset, Geography

dataset = Dataset.get(dataset_name)
geography = Geography.get(dataset.geography)

dataset, geography


Out[3]:
(<Dataset.get('ags_retailpoten_aaf25a8c')>,
 <Geography.get('cdb_blockgroup_7753dd51')>)

In [4]:
dataset.subscribe()



In [5]:
geography.subscribe()



In [6]:
Catalog().subscriptions()


Out[6]:
Datasets: [<Dataset.get('ags_businesscou_df363a87')>, <Dataset.get('ags_crimerisk_e9cfa4d4')>, <Dataset.get('ags_retailpoten_aaf25a8c')>, <Dataset.get('ags_sociodemogr_f510a947')>, <Dataset.get('ags_sociodemogr_a7e14220')>]
Geographies: [<Geography.get('cdb_blockgroup_7753dd51')>, <Geography.get('ags_blockgroup_1c63771c')>]

In [7]:
dataset.variables


Out[7]:
[<Variable.get('BLOCKGROUP_f1b3a750')> #'Geographic Identifier',
 <Variable.get('HHDCY_e7667366')> #'Households (2019A)',
 <Variable.get('MLTCY44111_aa03fac7')> #'New Car Dealers (Total Exp)',
 <Variable.get('MLTCY44112_330aab7d')> #'User Car Dealers (Total Exp)',
 <Variable.get('MLTCY44121_812ea904')> #'Recreational Vehicle Dealers (Total Exp)',
 <Variable.get('MLTCY44122_1827f8be')> #'Motorcycle and Boat Dealers (Total Exp)',
 <Variable.get('MLTCY44131_98359845')> #'Auto Parts and Accessories (Total Exp)',
 <Variable.get('MLTCY44132_13cc9ff')> #'Tire Dealers (Total Exp)',
 <Variable.get('MLTCY44211_a845449e')> #'Furniture Stores (Total Exp)',
 <Variable.get('MLTCY44221_8368175d')> #'Floor Covering Stores (Total Exp)',
 <Variable.get('MLTCY44229_8db39f6f')> #'Other Home Furnishing Stores (Total Exp)',
 <Variable.get('MLTCY44311_a9872ea9')> #'Appliances and Electronics Stores (Total Exp)',
 <Variable.get('MLTCY44411_acc8382c')> #'Home Centers (Total Exp)',
 <Variable.get('MLTCY44412_35c16996')> #'Paint and Wallpaper Stores (Total Exp)',
 <Variable.get('MLTCY44413_42c65900')> #'Hardware Stores (Total Exp)',
 <Variable.get('MLTCY44419_a213b01e')> #'Other Building Materials Stores (Total Exp)',
 <Variable.get('MLTCY44421_87e56bef')> #'Outdoor Power Equipment Stores (Total Exp)',
 <Variable.get('MLTCY44422_1eec3a55')> #'Nursery and Garden Stores (Total Exp)',
 <Variable.get('MLTCY44511_ad0a521b')> #'Grocery Stores (Total Exp)',
 <Variable.get('MLTCY44512_340303a1')> #'Convenience Stores (Total Exp)',
 <Variable.get('MLTCY44521_862701d8')> #'Meat Markets (Total Exp)',
 <Variable.get('MLTCY44522_1f2e5062')> #'Fish and Seafood Markets (Total Exp)',
 <Variable.get('MLTCY44523_682960f4')> #'Fruit and Vegetable Markets (Total Exp)',
 <Variable.get('MLTCY44529_88fc89ea')> #'Other Specialty Food Markets (Total Exp)',
 <Variable.get('MLTCY44531_9f3c3099')> #'Liquor Stores (Total Exp)',
 <Variable.get('MLTCY44611_af4cec42')> #'Pharmacy and Drug Stores (Total Exp)',
 <Variable.get('MLTCY44612_3645bdf8')> #'Costmetics and Beauty Stores (Total Exp)',
 <Variable.get('MLTCY44613_41428d6e')> #'Optical Goods Stores (Total Exp)',
 <Variable.get('MLTCY44619_a1976470')> #'Other Health and Personal Care Stores (Total Exp)',
 <Variable.get('MLTCY44719_a0550e47')> #'Gasoline Stations (Total Exp)',
 <Variable.get('MLTCY44811_a5d2c148')> #'Mens Clothing Stores (Total Exp)',
 <Variable.get('MLTCY44812_3cdb90f2')> #'Womens Clothing Stores (Total Exp)',
 <Variable.get('MLTCY44813_4bdca064')> #'Childrens and Infants Clothing Stores (Total Exp)',
 <Variable.get('MLTCY44814_d5b835c7')> #'Family Clothing Stores (Total Exp)',
 <Variable.get('MLTCY44815_a2bf0551')> #'Clothing Accessory Stores (Total Exp)',
 <Variable.get('MLTCY44819_ab09497a')> #'Other Apparel Stores (Total Exp)',
 <Variable.get('MLTCY44821_8eff928b')> #'Shoe Stores (Total Exp)',
 <Variable.get('MLTCY44831_97e4a3ca')> #'Jewelry Stores (Total Exp)',
 <Variable.get('MLTCY44832_eedf270')> #'Luggage Stores (Total Exp)',
 <Variable.get('MLTCY45111_12bf9da2')> #'Sporting Goods Stores (Total Exp)',
 <Variable.get('MLTCY45112_8bb6cc18')> #'Hobby, Toy, and Game Stores (Total Exp)',
 <Variable.get('MLTCY45113_fcb1fc8e')> #'Sewing and Needlecraft Stores (Total Exp)',
 <Variable.get('MLTCY45114_62d5692d')> #'Musical Instrument Stores (Total Exp)',
 <Variable.get('MLTCY45121_3992ce61')> #'Book Stores (Total Exp)',
 <Variable.get('MLTCY45211_10f923fb')> #'Department Stores (Total Exp)',
 <Variable.get('MLTCY45291_d820a9f3')> #'Warehouse Superstores (Total Exp)',
 <Variable.get('MLTCY45299_d6fb21c1')> #'Other General Merchandise Stores (Total Exp)',
 <Variable.get('MLTCY45311_113b49cc')> #'Florists (Total Exp)',
 <Variable.get('MLTCY45321_3a161a0f')> #'Office and Stationary Stores (Total Exp)',
 <Variable.get('MLTCY45322_a31f4bb5')> #'Gift and Souvenir Stores (Total Exp)',
 <Variable.get('MLTCY45331_230d2b4e')> #'Used Merchandise Stores (Total Exp)',
 <Variable.get('MLTCY45391_d9e2c3c4')> #'Pet and Pet Supply Stores (Total Exp)',
 <Variable.get('MLTCY45392_40eb927e')> #'Art Dealers (Total Exp)',
 <Variable.get('MLTCY45393_37eca2e8')> #'Mobile Home Dealers (Total Exp)',
 <Variable.get('MLTCY45399_d7394bf6')> #'Other Miscellaneous Retail Stores (Total Exp)',
 <Variable.get('MLTCY45411_14745f49')> #'Mail Order and Catalog Stores (Total Exp)',
 <Variable.get('MLTCY45421_3f590c8a')> #'Vending Machines (Total Exp)',
 <Variable.get('MLTCY45431_26423dcb')> #'Fuel Dealers (Total Exp)',
 <Variable.get('MLTCY45439_2899b5f9')> #'Other Direct Selling Establishments (Total Exp)',
 <Variable.get('MLTCY7211_10e43b25')> #'Retail at Hotels and Other Travel Accomodations (T...',
 <Variable.get('MLTCY7212_89ed6a9f')> #'Retail at RV Parks (Total Exp)',
 <Variable.get('MLTCY7213_feea5a09')> #'Retail at Rooming and Boarding Houses (Total Exp)',
 <Variable.get('MLTCY7221_3bc968e6')> #'Full Service Restaurants (Total Exp)',
 <Variable.get('MLTCY7222_a2c0395c')> #'Limited Service Restaurants (Total Exp)',
 <Variable.get('MLTCY7223_d5c709ca')> #'Special Food Services and Catering (Total Exp)',
 <Variable.get('MLTCY7224_4ba39c69')> #'Drinking Places (Total Exp)',
 <Variable.get('RSGCY44111_fdeb9bca')> #'Retail Gap: New Car Dealers (44111)',
 <Variable.get('RSGCY44112_64e2ca70')> #'Retail Gap: User Car Dealers (44112)',
 <Variable.get('RSGCY44121_d6c6c809')> #'Retail Gap: Recreational Vehicle Dealers (44121)',
 <Variable.get('RSGCY44122_4fcf99b3')> #'Retail Gap: Motorcycle and Boat Dealers (44122)',
 <Variable.get('RSGCY44131_cfddf948')> #'Retail Gap: Auto Parts and Accessories (44131)',
 <Variable.get('RSGCY44132_56d4a8f2')> #'Retail Gap: Tire Dealers (44132)',
 <Variable.get('RSGCY44211_ffad2593')> #'Retail Gap: Furniture Stores (44211)',
 <Variable.get('RSGCY44221_d4807650')> #'Retail Gap: Floor Covering Stores (44221)',
 <Variable.get('RSGCY44229_da5bfe62')> #'Retail Gap: Other Home Furnishing Stores (44229)',
 <Variable.get('RSGCY44311_fe6f4fa4')> #'Retail Gap: Appliances and Electronics Stores (443...',
 <Variable.get('RSGCY44411_fb205921')> #'Retail Gap: Home Centers (44411)',
 <Variable.get('RSGCY44412_6229089b')> #'Retail Gap: Paint and Wallpaper Stores (44412)',
 <Variable.get('RSGCY44413_152e380d')> #'Retail Gap: Hardware Stores (44413)',
 <Variable.get('RSGCY44419_f5fbd113')> #'Retail Gap: Other Building Materials Stores (44419...',
 <Variable.get('RSGCY44421_d00d0ae2')> #'Retail Gap: Outdoor Power Equipment Stores (44421)',
 <Variable.get('RSGCY44422_49045b58')> #'Retail Gap: Nursery and Garden Stores (44422)',
 <Variable.get('RSGCY44511_fae23316')> #'Retail Gap: Grocery Stores (44511)',
 <Variable.get('RSGCY44512_63eb62ac')> #'Retail Gap: Convenience Stores (44512)',
 <Variable.get('RSGCY44521_d1cf60d5')> #'Retail Gap: Meat Markets (44521)',
 <Variable.get('RSGCY44522_48c6316f')> #'Retail Gap: Fish and Seafood Markets (44522)',
 <Variable.get('RSGCY44523_3fc101f9')> #'Retail Gap: Fruit and Vegetable Markets (44523)',
 <Variable.get('RSGCY44529_df14e8e7')> #'Retail Gap: Other Specialty Food Markets (44529)',
 <Variable.get('RSGCY44531_c8d45194')> #'Retail Gap: Liquor Stores (44531)',
 <Variable.get('RSGCY44611_f8a48d4f')> #'Retail Gap: Pharmacy and Drug Stores (44611)',
 <Variable.get('RSGCY44612_61addcf5')> #'Retail Gap: Costmetics and Beauty Stores (44612)',
 <Variable.get('RSGCY44613_16aaec63')> #'Retail Gap: Optical Goods Stores (44613)',
 <Variable.get('RSGCY44619_f67f057d')> #'Retail Gap: Other Health and Personal Care Stores ...',
 <Variable.get('RSGCY44719_f7bd6f4a')> #'Retail Gap: Gasoline Stations (44719)',
 <Variable.get('RSGCY44811_f23aa045')> #'Retail Gap: Men's Clothing Stores (44811)',
 <Variable.get('RSGCY44812_6b33f1ff')> #'Retail Gap: Women's Clothing Stores (44812)',
 <Variable.get('RSGCY44813_1c34c169')> #'Retail Gap: Childrens' and Infant's Clothing Store...',
 <Variable.get('RSGCY44814_825054ca')> #'Retail Gap: Family Clothing Stores (44814)',
 <Variable.get('RSGCY44815_f557645c')> #'Retail Gap: Clothing Accessory Stores (44815)',
 <Variable.get('RSGCY44819_fce12877')> #'Retail Gap: Other Apparel Stores (44819)',
 <Variable.get('RSGCY44821_d917f386')> #'Retail Gap: Shoe Stores (44821)',
 <Variable.get('RSGCY44831_c00cc2c7')> #'Retail Gap: Jewelry Stores (44831)',
 <Variable.get('RSGCY44832_5905937d')> #'Retail Gap: Luggage Stores (44832)',
 <Variable.get('RSGCY45111_4557fcaf')> #'Retail Gap: Sporting Goods Stores (45111)',
 <Variable.get('RSGCY45112_dc5ead15')> #'Retail Gap: Hobby, Toy, and Game Stores (45112)',
 <Variable.get('RSGCY45113_ab599d83')> #'Retail Gap: Sewing and Needlecraft Stores (45113)',
 <Variable.get('RSGCY45114_353d0820')> #'Retail Gap: Musical Instrument Stores (45114)',
 <Variable.get('RSGCY45121_6e7aaf6c')> #'Retail Gap: Book Stores (45121)',
 <Variable.get('RSGCY45211_471142f6')> #'Retail Gap: Department Stores (45211)',
 <Variable.get('RSGCY45291_8fc8c8fe')> #'Retail Gap: Warehouse Superstores (45291)',
 <Variable.get('RSGCY45299_811340cc')> #'Retail Gap: Other General Merchandise Stores (4529...',
 <Variable.get('RSGCY45311_46d328c1')> #'Retail Gap: Florists (45311)',
 <Variable.get('RSGCY45321_6dfe7b02')> #'Retail Gap: Office and Stationary Stores (45321)',
 <Variable.get('RSGCY45322_f4f72ab8')> #'Retail Gap: Gift and Souvenir Stores (45322)',
 <Variable.get('RSGCY45331_74e54a43')> #'Retail Gap: Used Merchandise Stores (45331)',
 <Variable.get('RSGCY45391_8e0aa2c9')> #'Retail Gap: Pet and Pet Supply Stores (45391)',
 <Variable.get('RSGCY45392_1703f373')> #'Retail Gap: Art Dealers (45392)',
 <Variable.get('RSGCY45393_6004c3e5')> #'Retail Gap: Mobile Home Dealers (45393)',
 <Variable.get('RSGCY45399_80d12afb')> #'Retail Gap: Other Miscellaneous Retail Stores (453...',
 <Variable.get('RSGCY45411_439c3e44')> #'Retail Gap: Mail Order and Catalog Stores (45411)',
 <Variable.get('RSGCY45421_68b16d87')> #'Retail Gap: Vending Machines (45421)',
 <Variable.get('RSGCY45431_71aa5cc6')> #'Retail Gap: Fuel Dealers (45431)',
 <Variable.get('RSGCY45439_7f71d4f4')> #'Retail Gap: Other Direct Selling Establishments (4...',
 <Variable.get('RSGCY7211_90301351')> #'Retail Gap: Retail at Hotels and Other Travel Acco...',
 <Variable.get('RSGCY7212_93942eb')> #'Retail Gap: Retail at RV Parks (7212)',
 <Variable.get('RSGCY7213_7e3e727d')> #'Retail Gap: Retail at Rooming and Boarding Houses ...',
 <Variable.get('RSGCY7221_bb1d4092')> #'Retail Gap: Full Service Restaurants (7221)',
 <Variable.get('RSGCY7222_22141128')> #'Retail Gap: Limited Service Restaurants (7222)',
 <Variable.get('RSGCY7223_551321be')> #'Retail Gap: Special Food Services and Catering (72...',
 <Variable.get('RSGCY7224_cb77b41d')> #'Retail Gap: Drinking Places (7224)']

In [8]:
from cartoframes.data.observatory import Variable

variable = Variable.get('MLTCY44411_acc8382c')
variable


Out[8]:
<Variable.get('MLTCY44411_acc8382c')> #'Home Centers (Total Exp)'

In [9]:
from geopandas import read_file

census_track = 'http://libs.cartocdn.com/cartoframes/files/census_track.geojson'
census_track_gdf = read_file(census_track)
census_track_gdf.head(3)


Out[9]:
OBJECTID FULLTRACTID TRACTID geometry
0 1 51013102901 102901 POLYGON ((-77.09099 38.84516, -77.08957 38.844...
1 2 51013103000 103000 POLYGON ((-77.08558 38.82992, -77.08625 38.828...
2 3 51013102902 102902 POLYGON ((-77.09520 38.84499, -77.09442 38.844...

In [10]:
from cartoframes.data.observatory import Enrichment

enrichment = Enrichment()

enriched_dataset_gdf = enrichment.enrich_polygons(
    census_track_gdf,
    variables=['MLTCY44411_acc8382c']
)

In [11]:
enriched_dataset_gdf.head(3)


Out[11]:
OBJECTID FULLTRACTID TRACTID geometry MLTCY44411
0 1 51013102901 102901 POLYGON ((-77.09099 38.84516, -77.08957 38.844... 1.862995e+06
1 2 51013103000 103000 POLYGON ((-77.08558 38.82992, -77.08625 38.828... 2.099457e+06
2 3 51013102902 102902 POLYGON ((-77.09520 38.84499, -77.09442 38.844... 2.671894e+06

In [12]:
from cartoframes.viz import Layer, color_continuous_style

Layer(enriched_dataset_gdf, color_continuous_style('MLTCY44411'))


Out[12]:
:
StackTrace