This example illustrates how simply use the Geocoding Data Service.
Note: You'll need CARTO Account credentials to reproduce this example.
from cartoframes.auth import set_default_credentials
set_default_credentials('creds.json')
from pandas import DataFrame
df = DataFrame([['Gran Vía 46', 'Madrid'], ['Ebro 1', 'Sevilla']], columns=['address','city'])
df
address | city | |
---|---|---|
0 | Gran Vía 46 | Madrid |
1 | Ebro 1 | Sevilla |
from cartoframes.data.services import Geocoding
gc = Geocoding()
gdf, metadata = gc.geocode(df, street='address', city='city', country={'value': 'Spain'})
Success! Data geocoded correctly
gdf
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 |
metadata
{'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}
from cartoframes.viz import Layer
Layer(gdf)