{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Enrichment Subscription Workflow\n",
"\n",
"This example illustrates how to subscribe and enrich with CARTO's Data Observatory.\n",
"\n",
"_Note: You'll need [CARTO Account](https://carto.com/signup) credentials to reproduce this example._"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from cartoframes.auth import set_default_credentials\n",
"\n",
"set_default_credentials('creds.json')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"dataset_name = 'carto-do.ags.demographics_retailpotential_usa_blockgroup_2015_yearly_2019'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from cartoframes.data.observatory import Catalog, Dataset, Geography\n",
"\n",
"dataset = Dataset.get(dataset_name)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "01229efd49bb493db0108acc19d7dc92",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HTML(value='\\n
Subscription already purchased
\\n The dataset carto-do.ags.demographic…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dataset.subscribe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NOTE: After the subscription request of the premium dataset, we will contact you to **perform and complete the premium subscription**. When the process is completed, you will be able to access your premium dataset directly from CARTOframes or from the Dashboard in your CARTO account."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Datasets: [, ]\n",
"Geographies: []"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Catalog().subscriptions()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[ #'Geographic Identifier',\n",
" #'Households (2019A)',\n",
" #'New Car Dealers (Total Exp)',\n",
" #'User Car Dealers (Total Exp)',\n",
" #'Recreational Vehicle Dealers (Total Exp)',\n",
" #'Motorcycle and Boat Dealers (Total Exp)',\n",
" #'Auto Parts and Accessories (Total Exp)',\n",
" #'Tire Dealers (Total Exp)',\n",
" #'Furniture Stores (Total Exp)',\n",
" #'Floor Covering Stores (Total Exp)',\n",
" #'Other Home Furnishing Stores (Total Exp)',\n",
" #'Appliances and Electronics Stores (Total Exp)',\n",
" #'Home Centers (Total Exp)',\n",
" #'Paint and Wallpaper Stores (Total Exp)',\n",
" #'Hardware Stores (Total Exp)',\n",
" #'Other Building Materials Stores (Total Exp)',\n",
" #'Outdoor Power Equipment Stores (Total Exp)',\n",
" #'Nursery and Garden Stores (Total Exp)',\n",
" #'Grocery Stores (Total Exp)',\n",
" #'Convenience Stores (Total Exp)',\n",
" #'Meat Markets (Total Exp)',\n",
" #'Fish and Seafood Markets (Total Exp)',\n",
" #'Fruit and Vegetable Markets (Total Exp)',\n",
" #'Other Specialty Food Markets (Total Exp)',\n",
" #'Liquor Stores (Total Exp)',\n",
" #'Pharmacy and Drug Stores (Total Exp)',\n",
" #'Costmetics and Beauty Stores (Total Exp)',\n",
" #'Optical Goods Stores (Total Exp)',\n",
" #'Other Health and Personal Care Stores (Total Exp)',\n",
" #'Gasoline Stations (Total Exp)',\n",
" #'Mens Clothing Stores (Total Exp)',\n",
" #'Womens Clothing Stores (Total Exp)',\n",
" #'Childrens and Infants Clothing Stores (Total Exp)',\n",
" #'Family Clothing Stores (Total Exp)',\n",
" #'Clothing Accessory Stores (Total Exp)',\n",
" #'Other Apparel Stores (Total Exp)',\n",
" #'Shoe Stores (Total Exp)',\n",
" #'Jewelry Stores (Total Exp)',\n",
" #'Luggage Stores (Total Exp)',\n",
" #'Sporting Goods Stores (Total Exp)',\n",
" #'Hobby, Toy, and Game Stores (Total Exp)',\n",
" #'Sewing and Needlecraft Stores (Total Exp)',\n",
" #'Musical Instrument Stores (Total Exp)',\n",
" #'Book Stores (Total Exp)',\n",
" #'Department Stores (Total Exp)',\n",
" #'Warehouse Superstores (Total Exp)',\n",
" #'Other General Merchandise Stores (Total Exp)',\n",
" #'Florists (Total Exp)',\n",
" #'Office and Stationary Stores (Total Exp)',\n",
" #'Gift and Souvenir Stores (Total Exp)',\n",
" #'Used Merchandise Stores (Total Exp)',\n",
" #'Pet and Pet Supply Stores (Total Exp)',\n",
" #'Art Dealers (Total Exp)',\n",
" #'Mobile Home Dealers (Total Exp)',\n",
" #'Other Miscellaneous Retail Stores (Total Exp)',\n",
" #'Mail Order and Catalog Stores (Total Exp)',\n",
" #'Vending Machines (Total Exp)',\n",
" #'Fuel Dealers (Total Exp)',\n",
" #'Other Direct Selling Establishments (Total Exp)',\n",
" #'Retail at Hotels and Other Travel Accomodations (T...',\n",
" #'Retail at RV Parks (Total Exp)',\n",
" #'Retail at Rooming and Boarding Houses (Total Exp)',\n",
" #'Full Service Restaurants (Total Exp)',\n",
" #'Limited Service Restaurants (Total Exp)',\n",
" #'Special Food Services and Catering (Total Exp)',\n",
" #'Drinking Places (Total Exp)',\n",
" #'Retail Gap: New Car Dealers (44111)',\n",
" #'Retail Gap: User Car Dealers (44112)',\n",
" #'Retail Gap: Recreational Vehicle Dealers (44121)',\n",
" #'Retail Gap: Motorcycle and Boat Dealers (44122)',\n",
" #'Retail Gap: Auto Parts and Accessories (44131)',\n",
" #'Retail Gap: Tire Dealers (44132)',\n",
" #'Retail Gap: Furniture Stores (44211)',\n",
" #'Retail Gap: Floor Covering Stores (44221)',\n",
" #'Retail Gap: Other Home Furnishing Stores (44229)',\n",
" #'Retail Gap: Appliances and Electronics Stores (443...',\n",
" #'Retail Gap: Home Centers (44411)',\n",
" #'Retail Gap: Paint and Wallpaper Stores (44412)',\n",
" #'Retail Gap: Hardware Stores (44413)',\n",
" #'Retail Gap: Other Building Materials Stores (44419...',\n",
" #'Retail Gap: Outdoor Power Equipment Stores (44421)',\n",
" #'Retail Gap: Nursery and Garden Stores (44422)',\n",
" #'Retail Gap: Grocery Stores (44511)',\n",
" #'Retail Gap: Convenience Stores (44512)',\n",
" #'Retail Gap: Meat Markets (44521)',\n",
" #'Retail Gap: Fish and Seafood Markets (44522)',\n",
" #'Retail Gap: Fruit and Vegetable Markets (44523)',\n",
" #'Retail Gap: Other Specialty Food Markets (44529)',\n",
" #'Retail Gap: Liquor Stores (44531)',\n",
" #'Retail Gap: Pharmacy and Drug Stores (44611)',\n",
" #'Retail Gap: Costmetics and Beauty Stores (44612)',\n",
" #'Retail Gap: Optical Goods Stores (44613)',\n",
" #'Retail Gap: Other Health and Personal Care Stores ...',\n",
" #'Retail Gap: Gasoline Stations (44719)',\n",
" #'Retail Gap: Men's Clothing Stores (44811)',\n",
" #'Retail Gap: Women's Clothing Stores (44812)',\n",
" #'Retail Gap: Childrens' and Infant's Clothing Store...',\n",
" #'Retail Gap: Family Clothing Stores (44814)',\n",
" #'Retail Gap: Clothing Accessory Stores (44815)',\n",
" #'Retail Gap: Other Apparel Stores (44819)',\n",
" #'Retail Gap: Shoe Stores (44821)',\n",
" #'Retail Gap: Jewelry Stores (44831)',\n",
" #'Retail Gap: Luggage Stores (44832)',\n",
" #'Retail Gap: Sporting Goods Stores (45111)',\n",
" #'Retail Gap: Hobby, Toy, and Game Stores (45112)',\n",
" #'Retail Gap: Sewing and Needlecraft Stores (45113)',\n",
" #'Retail Gap: Musical Instrument Stores (45114)',\n",
" #'Retail Gap: Book Stores (45121)',\n",
" #'Retail Gap: Department Stores (45211)',\n",
" #'Retail Gap: Warehouse Superstores (45291)',\n",
" #'Retail Gap: Other General Merchandise Stores (4529...',\n",
" #'Retail Gap: Florists (45311)',\n",
" #'Retail Gap: Office and Stationary Stores (45321)',\n",
" #'Retail Gap: Gift and Souvenir Stores (45322)',\n",
" #'Retail Gap: Used Merchandise Stores (45331)',\n",
" #'Retail Gap: Pet and Pet Supply Stores (45391)',\n",
" #'Retail Gap: Art Dealers (45392)',\n",
" #'Retail Gap: Mobile Home Dealers (45393)',\n",
" #'Retail Gap: Other Miscellaneous Retail Stores (453...',\n",
" #'Retail Gap: Mail Order and Catalog Stores (45411)',\n",
" #'Retail Gap: Vending Machines (45421)',\n",
" #'Retail Gap: Fuel Dealers (45431)',\n",
" #'Retail Gap: Other Direct Selling Establishments (4...',\n",
" #'Retail Gap: Retail at Hotels and Other Travel Acco...',\n",
" #'Retail Gap: Retail at RV Parks (7212)',\n",
" #'Retail Gap: Retail at Rooming and Boarding Houses ...',\n",
" #'Retail Gap: Full Service Restaurants (7221)',\n",
" #'Retail Gap: Limited Service Restaurants (7222)',\n",
" #'Retail Gap: Special Food Services and Catering (72...',\n",
" #'Retail Gap: Drinking Places (7224)',\n",
" #'Geographical Identifier',\n",
" #'First day of time period']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dataset.variables"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" #'Home Centers (Total Exp)'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from cartoframes.data.observatory import Variable\n",
"\n",
"variable = Variable.get('MLTCY44411_acc8382c')\n",
"variable"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" OBJECTID | \n",
" FULLTRACTID | \n",
" TRACTID | \n",
" geometry | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 51013102901 | \n",
" 102901 | \n",
" POLYGON ((-77.09099 38.84516, -77.08957 38.844... | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 51013103000 | \n",
" 103000 | \n",
" POLYGON ((-77.08558 38.82992, -77.08625 38.828... | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 51013102902 | \n",
" 102902 | \n",
" POLYGON ((-77.09520 38.84499, -77.09442 38.844... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" OBJECTID FULLTRACTID TRACTID \\\n",
"0 1 51013102901 102901 \n",
"1 2 51013103000 103000 \n",
"2 3 51013102902 102902 \n",
"\n",
" geometry \n",
"0 POLYGON ((-77.09099 38.84516, -77.08957 38.844... \n",
"1 POLYGON ((-77.08558 38.82992, -77.08625 38.828... \n",
"2 POLYGON ((-77.09520 38.84499, -77.09442 38.844... "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from geopandas import read_file\n",
"\n",
"census_track = 'http://libs.cartocdn.com/cartoframes/files/census_track.geojson'\n",
"census_track_gdf = read_file(census_track)\n",
"census_track_gdf.head(3)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from cartoframes.data.observatory import Enrichment\n",
"\n",
"enrichment = Enrichment()\n",
"\n",
"enriched_dataset_gdf = enrichment.enrich_polygons(\n",
" census_track_gdf,\n",
" variables=['MLTCY44411_acc8382c']\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" OBJECTID | \n",
" FULLTRACTID | \n",
" TRACTID | \n",
" geometry | \n",
" MLTCY44411 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 51013102901 | \n",
" 102901 | \n",
" POLYGON ((-77.09099 38.84516, -77.08957 38.844... | \n",
" 1.862995e+06 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 51013103000 | \n",
" 103000 | \n",
" POLYGON ((-77.08558 38.82992, -77.08625 38.828... | \n",
" 2.099457e+06 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 51013102902 | \n",
" 102902 | \n",
" POLYGON ((-77.09520 38.84499, -77.09442 38.844... | \n",
" 2.671894e+06 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" OBJECTID FULLTRACTID TRACTID \\\n",
"0 1 51013102901 102901 \n",
"1 2 51013103000 103000 \n",
"2 3 51013102902 102902 \n",
"\n",
" geometry MLTCY44411 \n",
"0 POLYGON ((-77.09099 38.84516, -77.08957 38.844... 1.862995e+06 \n",
"1 POLYGON ((-77.08558 38.82992, -77.08625 38.828... 2.099457e+06 \n",
"2 POLYGON ((-77.09520 38.84499, -77.09442 38.844... 2.671894e+06 "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"enriched_dataset_gdf.head(3)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from cartoframes.viz import Layer, color_continuous_style\n",
"\n",
"Layer(enriched_dataset_gdf, color_continuous_style('MLTCY44411'))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}