Geocode a DataFrame

This example illustrates how simply use the Geocoding Data Service

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


In [13]:
from cartoframes.auth import set_default_credentials

set_default_credentials('creds.json')

In [14]:
import pandas

df = pandas.DataFrame([['Gran Vía 46', 'Madrid'], ['Ebro 1', 'Sevilla']], columns=['address','city'])
df


Out[14]:
address city
0 Gran Vía 46 Madrid
1 Ebro 1 Sevilla

In [15]:
from cartoframes.data.services import Geocoding

gc = Geocoding()
gdf, metadata = gc.geocode(df, street='address', city='city', country={'value': 'Spain'})


Success! Data geocoded correctly

In [16]:
gdf


Out[16]:
the_geom address city gc_status_rel carto_geocode_hash
0 POINT (-3.70588 40.42049) Gran Vía 46 Madrid 0.84 95e4f39284efeab8e759aaa547d84567
1 POINT (-5.98312 37.35547) Ebro 1 Sevilla 0.70 66940c4beeb395e1b628587ac772763a

In [17]:
metadata


Out[17]:
{'total_rows': 2,
 'required_quota': 2,
 'previously_geocoded': 0,
 'previously_failed': 0,
 'records_with_geometry': 0,
 'final_records_with_geometry': 2,
 'geocoded_increment': 2,
 'successfully_geocoded': 2,
 'failed_geocodings': 0}

In [18]:
from cartoframes.viz import Layer

Layer(gdf)


Out[18]:
:
StackTrace
    ">