Getting started with CARTOframes

1. Connect to a CARTO account

  • creds.json file sample:
{
    username: 'john-smith',
    api_key: '1a2b3c4d5e6f7g8h'
}

In [6]:
from cartoframes.auth import set_default_credentials

set_default_credentials('creds.json')

2. Enrich your data


In [9]:
from cartoframes.data.observatory import Enrichment
from cartoframes.data.services import Geocoding, Isolines
import pandas as pd

stores_df = pd.read_csv('http://libs.cartocdn.com/cartoframes/files/starbucks_brooklyn.csv')
stores_gdf, _ = Geocoding().geocode(stores_df, street='address')
aoi_gdf, _ = Isolines().isochrones(stores_gdf, [15*60], mode='walk')
aoi_enriched_gdf = Enrichment().enrich_polygons(aoi_gdf, ['total_pop_3cf008b3'])


Success! Data geocoded correctly
Success! Isolines created correctly

3. Create a visualization


In [11]:
from cartoframes.viz import Map, Layer, color_continuous_style, size_continuous_style

result_map = Map([
    Layer(aoi_enriched_gdf, color_continuous_style('total_pop', stroke_width=0, opacity=0.7)),
    Layer(stores_gdf, size_continuous_style('revenue', stroke_color='white'), default_widget=True)
])

result_map


Out[11]:

There is a from the CARTO VL library:

:
StackTrace
    ">

    4. Share your visualization

    
    
    In [12]:
    result_map.publish('onboarding_analysis', password=None, if_exists='replace')
    
    
    
    
    Out[12]:
    {'id': '6390ec30-960e-4752-9cd4-6e2a2eafe632',
     'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/6390ec30-960e-4752-9cd4-6e2a2eafe632',
     'name': 'onboarding_analysis',
     'privacy': 'public'}