{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Geocode a DataFrame\n", "\n", "This example illustrates how simply use the Geocoding Data Service.\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": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
addresscity
0Gran Vía 46Madrid
1Ebro 1Sevilla
\n", "
" ], "text/plain": [ " address city\n", "0 Gran Vía 46 Madrid\n", "1 Ebro 1 Sevilla" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pandas import DataFrame\n", "\n", "df = DataFrame([['Gran Vía 46', 'Madrid'], ['Ebro 1', 'Sevilla']], columns=['address','city'])\n", "df" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Success! Data geocoded correctly\n" ] } ], "source": [ "from cartoframes.data.services import Geocoding\n", "\n", "gc = Geocoding()\n", "gdf, metadata = gc.geocode(df, street='address', city='city', country={'value': 'Spain'})" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
the_geomaddresscitygc_status_relcarto_geocode_hash
0POINT (-3.70588 40.42049)Gran Vía 46Madrid0.8495e4f39284efeab8e759aaa547d84567
1POINT (-5.98312 37.35547)Ebro 1Sevilla0.7066940c4beeb395e1b628587ac772763a
\n", "
" ], "text/plain": [ " the_geom address city gc_status_rel \\\n", "0 POINT (-3.70588 40.42049) Gran Vía 46 Madrid 0.84 \n", "1 POINT (-5.98312 37.35547) Ebro 1 Sevilla 0.70 \n", "\n", " carto_geocode_hash \n", "0 95e4f39284efeab8e759aaa547d84567 \n", "1 66940c4beeb395e1b628587ac772763a " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gdf" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'total_rows': 2,\n", " 'required_quota': 2,\n", " 'previously_geocoded': 0,\n", " 'previously_failed': 0,\n", " 'records_with_geometry': 0,\n", " 'final_records_with_geometry': 2,\n", " 'geocoded_increment': 2,\n", " 'successfully_geocoded': 2,\n", " 'failed_geocodings': 0}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "metadata" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " None\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " Static map image\n", " \n", " \n", "
\n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", "
\n", "\n", " \n", "\n", "
\n", "
\n", " :\n", "
\n", " \n", " \n", "
\n", "
\n", "\n", "
\n", " StackTrace\n", "
    \n", "
    \n", "
    \n", "\n", "\n", "\n", "\n", "\n", "\">\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.viz import Layer\n", "\n", "Layer(gdf)" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }