Skip to content

Instantly share code, notes, and snippets.

@j-jayes
Last active October 2, 2023 12:18
Show Gist options
  • Select an option

  • Save j-jayes/b5c1108cdb8da134d6552ef185dbf787 to your computer and use it in GitHub Desktop.

Select an option

Save j-jayes/b5c1108cdb8da134d6552ef185dbf787 to your computer and use it in GitHub Desktop.
geocoding_in_python.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyP6woWYj/fs+ZH5qmp37fYC",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/j-jayes/b5c1108cdb8da134d6552ef185dbf787/geocoding_in_python.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Geocoding and Visualizing Place Names\n",
"\n",
"In this notebook, we'll be using the Google Maps Geocoding API to convert place names from a CSV file into geographic coordinates. We will then visualize these locations on a map using Folium and save the geocoded results to a new CSV file.\n",
"\n",
"## Import Necessary Libraries\n"
],
"metadata": {
"id": "VcADi5x2GUzV"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "OMSw3h8eGQG2"
},
"outputs": [],
"source": [
"# Import necessary libraries\n",
"import requests # To make API requests\n",
"import pandas as pd # To handle CSV files and dataframes\n",
"import folium # To visualize data on a map\n",
"from folium import Marker\n"
]
},
{
"cell_type": "markdown",
"source": [
"## Load the Data\n",
"\n",
"Let's start by loading the data from the CSV file.\n"
],
"metadata": {
"id": "1GYvQIwKGYWE"
}
},
{
"cell_type": "code",
"source": [
"# Load the CSV file into a DataFrame\n",
"filename = 'https://raw.githubusercontent.com/j-jayes/interlude-one/main/posts/2023-10-02-geocoding/data/places_to_geocode.csv' # Replace with your CSV file containing place names.\n",
"df = pd.read_csv(filename, delimiter=';')\n",
"\n",
"# Display the first few rows of the dataframe\n",
"df.head()\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 248
},
"id": "yS5txkx8GXPj",
"outputId": "098221c5-ed63-4365-8b54-d652d3b1a303"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" place_name arbitrary_value\n",
"0 Stockholm 35\n",
"1 Gothenburg 12\n",
"2 Malmö 27\n",
"3 Uppsala 19\n",
"4 Västerås 22"
],
"text/html": [
"\n",
" <div id=\"df-ba987f66-6d96-471d-aa64-d8608a071a1f\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>place_name</th>\n",
" <th>arbitrary_value</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Stockholm</td>\n",
" <td>35</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Gothenburg</td>\n",
" <td>12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Malmö</td>\n",
" <td>27</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Uppsala</td>\n",
" <td>19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Västerås</td>\n",
" <td>22</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-ba987f66-6d96-471d-aa64-d8608a071a1f')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-ba987f66-6d96-471d-aa64-d8608a071a1f button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-ba987f66-6d96-471d-aa64-d8608a071a1f');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-38b6c739-d943-4af6-82c5-8d918f5b0d23\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-38b6c739-d943-4af6-82c5-8d918f5b0d23')\"\n",
" title=\"Suggest charts.\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-38b6c739-d943-4af6-82c5-8d918f5b0d23 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
" </div>\n",
" </div>\n"
]
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "markdown",
"source": [
"## Geocoding\n",
"\n",
"Now, let's use the Google Maps Geocoding API to get the latitude and longitude for each place name in our DataFrame.\n"
],
"metadata": {
"id": "rZpaNfVjGd9p"
}
},
{
"cell_type": "code",
"source": [
"# Define the geocoding function\n",
"def geocode(address, api_key):\n",
" url = 'https://maps.googleapis.com/maps/api/geocode/json'\n",
" params = {'address': address, 'key': api_key}\n",
" response = requests.get(url, params=params)\n",
" data = response.json()\n",
" if data['status'] == 'OK':\n",
" lat = data['results'][0]['geometry']['location']['lat']\n",
" lng = data['results'][0]['geometry']['location']['lng']\n",
" return lat, lng\n",
" else:\n",
" return None, None\n",
"\n",
"# Add columns for latitude and longitude\n",
"df['Latitude'] = None\n",
"df['Longitude'] = None\n",
"\n",
"# Google Maps Geocoding API key\n",
"api_key = 'YOUR_GOOGLE_API_KEY' # Replace with your Google API key\n",
"\n",
"# Loop over the rows and geocode each address\n",
"for idx, row in df.iterrows():\n",
" address = row['place_name'] # Replace 'place_name' with the name of the column containing the place names.\n",
" lat, lng = geocode(address, api_key)\n",
" df.loc[idx, 'Latitude'] = lat\n",
" df.loc[idx, 'Longitude'] = lng\n",
"\n",
"# Display the first few rows of the updated dataframe\n",
"df.head()\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "fvWM7r6WGg_A",
"outputId": "893c16de-be7d-409a-92cd-7c7b08ca75c5"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" place_name arbitrary_value Latitude Longitude\n",
"0 Stockholm 35 59.329323 18.068581\n",
"1 Gothenburg 12 57.70887 11.97456\n",
"2 Malmö 27 55.604981 13.003822\n",
"3 Uppsala 19 59.858564 17.638927\n",
"4 Västerås 22 59.6099 16.544809"
],
"text/html": [
"\n",
" <div id=\"df-b6a8de81-e455-4530-908d-54c1cf0f300d\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>place_name</th>\n",
" <th>arbitrary_value</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Stockholm</td>\n",
" <td>35</td>\n",
" <td>59.329323</td>\n",
" <td>18.068581</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Gothenburg</td>\n",
" <td>12</td>\n",
" <td>57.70887</td>\n",
" <td>11.97456</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Malmö</td>\n",
" <td>27</td>\n",
" <td>55.604981</td>\n",
" <td>13.003822</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Uppsala</td>\n",
" <td>19</td>\n",
" <td>59.858564</td>\n",
" <td>17.638927</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Västerås</td>\n",
" <td>22</td>\n",
" <td>59.6099</td>\n",
" <td>16.544809</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b6a8de81-e455-4530-908d-54c1cf0f300d')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-b6a8de81-e455-4530-908d-54c1cf0f300d button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-b6a8de81-e455-4530-908d-54c1cf0f300d');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-9d193313-a4d4-4d9c-8e58-21c4ebaa0008\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-9d193313-a4d4-4d9c-8e58-21c4ebaa0008')\"\n",
" title=\"Suggest charts.\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-9d193313-a4d4-4d9c-8e58-21c4ebaa0008 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
" </div>\n",
" </div>\n"
]
},
"metadata": {},
"execution_count": 4
}
]
},
{
"cell_type": "markdown",
"source": [
"## Visualizing Geocoded Data\n",
"\n",
"Let's visualize the geocoded data on a map using Folium. The map will automatically zoom to the bounds of the geocoded locations, and each marker's popup will display the place name and the arbitrary value associated with that location.\n",
"\n"
],
"metadata": {
"id": "n2YhHeOBGj3b"
}
},
{
"cell_type": "code",
"source": [
"# Create a base map; initially centered on a default location\n",
"m = folium.Map(location=[20,0], zoom_start=2)\n",
"\n",
"# List to hold the lat-long values, which will be used to fit the map to bounds of the data.\n",
"lat_lng_list = []\n",
"\n",
"# Add markers to the map for each geocoded location\n",
"for idx, row in df.iterrows():\n",
" if row['Latitude'] and row['Longitude']:\n",
" # Appending the latitude, longitude values to lat_lng_list\n",
" lat_lng_list.append([row['Latitude'], row['Longitude']])\n",
"\n",
" # Creating a popup string containing place name and arbitrary value\n",
" popup_str = f\"{row['place_name']}<br>Arbitrary Value: {row['arbitrary_value']}\"\n",
"\n",
" # Adding a marker to the map with the popup\n",
" Marker([row['Latitude'], row['Longitude']], popup=popup_str).add_to(m)\n",
"\n",
"# Fitting the map to the bounds of the geocoded locations\n",
"if lat_lng_list:\n",
" m.fit_bounds(lat_lng_list)\n",
"\n",
"# Display the map\n",
"m\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "NON_lJJXGlEB",
"outputId": "344ab88a-0f5d-472b-ab0f-a1453c5b931a"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<folium.folium.Map at 0x7fddcc82ea10>"
],
"text/html": [
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe srcdoc=\"&lt;!DOCTYPE html&gt;\n",
"&lt;html&gt;\n",
"&lt;head&gt;\n",
" \n",
" &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;\n",
" \n",
" &lt;script&gt;\n",
" L_NO_TOUCH = false;\n",
" L_DISABLE_3D = false;\n",
" &lt;/script&gt;\n",
" \n",
" &lt;style&gt;html, body {width: 100%;height: 100%;margin: 0;padding: 0;}&lt;/style&gt;\n",
" &lt;style&gt;#map {position:absolute;top:0;bottom:0;right:0;left:0;}&lt;/style&gt;\n",
" &lt;script src=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js&quot;&gt;&lt;/script&gt;\n",
" &lt;script src=&quot;https://code.jquery.com/jquery-1.12.4.min.js&quot;&gt;&lt;/script&gt;\n",
" &lt;script src=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;\n",
" &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js&quot;&gt;&lt;/script&gt;\n",
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css&quot;/&gt;\n",
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css&quot;/&gt;\n",
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css&quot;/&gt;\n",
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css&quot;/&gt;\n",
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css&quot;/&gt;\n",
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css&quot;/&gt;\n",
" \n",
" &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,\n",
" initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot; /&gt;\n",
" &lt;style&gt;\n",
" #map_55a6f4f8a1b66703984981c5543b4276 {\n",
" position: relative;\n",
" width: 100.0%;\n",
" height: 100.0%;\n",
" left: 0.0%;\n",
" top: 0.0%;\n",
" }\n",
" .leaflet-container { font-size: 1rem; }\n",
" &lt;/style&gt;\n",
" \n",
"&lt;/head&gt;\n",
"&lt;body&gt;\n",
" \n",
" \n",
" &lt;div class=&quot;folium-map&quot; id=&quot;map_55a6f4f8a1b66703984981c5543b4276&quot; &gt;&lt;/div&gt;\n",
" \n",
"&lt;/body&gt;\n",
"&lt;script&gt;\n",
" \n",
" \n",
" var map_55a6f4f8a1b66703984981c5543b4276 = L.map(\n",
" &quot;map_55a6f4f8a1b66703984981c5543b4276&quot;,\n",
" {\n",
" center: [20.0, 0.0],\n",
" crs: L.CRS.EPSG3857,\n",
" zoom: 2,\n",
" zoomControl: true,\n",
" preferCanvas: false,\n",
" }\n",
" );\n",
"\n",
" \n",
"\n",
" \n",
" \n",
" var tile_layer_66819e66d51d3b59354798653de25840 = L.tileLayer(\n",
" &quot;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&quot;,\n",
" {&quot;attribution&quot;: &quot;Data by \\u0026copy; \\u003ca target=\\&quot;_blank\\&quot; href=\\&quot;http://openstreetmap.org\\&quot;\\u003eOpenStreetMap\\u003c/a\\u003e, under \\u003ca target=\\&quot;_blank\\&quot; href=\\&quot;http://www.openstreetmap.org/copyright\\&quot;\\u003eODbL\\u003c/a\\u003e.&quot;, &quot;detectRetina&quot;: false, &quot;maxNativeZoom&quot;: 18, &quot;maxZoom&quot;: 18, &quot;minZoom&quot;: 0, &quot;noWrap&quot;: false, &quot;opacity&quot;: 1, &quot;subdomains&quot;: &quot;abc&quot;, &quot;tms&quot;: false}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var marker_4216045b8dd75778741378162ea097b4 = L.marker(\n",
" [59.32932349999999, 18.0685808],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_d9299c47ffcc59397c8cfd5e2db3b03a = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_4443ad421505013474c1f2584d4efac6 = $(`&lt;div id=&quot;html_4443ad421505013474c1f2584d4efac6&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Stockholm &lt;br&gt;Arbitrary Value: 35&lt;/div&gt;`)[0];\n",
" popup_d9299c47ffcc59397c8cfd5e2db3b03a.setContent(html_4443ad421505013474c1f2584d4efac6);\n",
" \n",
" \n",
"\n",
" marker_4216045b8dd75778741378162ea097b4.bindPopup(popup_d9299c47ffcc59397c8cfd5e2db3b03a)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_5c9b01527226b7a37d74e47b96f9abe5 = L.marker(\n",
" [57.70887, 11.97456],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_b3ea3d1b794d7e70ce672f42e84f91d0 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_34ceb354ea9b00b1ce16dd63c9a577f2 = $(`&lt;div id=&quot;html_34ceb354ea9b00b1ce16dd63c9a577f2&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Gothenburg &lt;br&gt;Arbitrary Value: 12&lt;/div&gt;`)[0];\n",
" popup_b3ea3d1b794d7e70ce672f42e84f91d0.setContent(html_34ceb354ea9b00b1ce16dd63c9a577f2);\n",
" \n",
" \n",
"\n",
" marker_5c9b01527226b7a37d74e47b96f9abe5.bindPopup(popup_b3ea3d1b794d7e70ce672f42e84f91d0)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_dc284c506084643a8fe9be5a9478b7d0 = L.marker(\n",
" [55.604981, 13.003822],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_0011d68ef13fe669a5912f4f9425c6f8 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_d3ca20056472949b93f92f32f284a97a = $(`&lt;div id=&quot;html_d3ca20056472949b93f92f32f284a97a&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Malmö &lt;br&gt;Arbitrary Value: 27&lt;/div&gt;`)[0];\n",
" popup_0011d68ef13fe669a5912f4f9425c6f8.setContent(html_d3ca20056472949b93f92f32f284a97a);\n",
" \n",
" \n",
"\n",
" marker_dc284c506084643a8fe9be5a9478b7d0.bindPopup(popup_0011d68ef13fe669a5912f4f9425c6f8)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_7191d0497dcc99b03ff7c3f59679747c = L.marker(\n",
" [59.85856380000001, 17.6389267],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_3de3322fefe510d43316c12c9513d4e6 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_8464238f3f66d27f35c25aa2bd214c78 = $(`&lt;div id=&quot;html_8464238f3f66d27f35c25aa2bd214c78&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Uppsala &lt;br&gt;Arbitrary Value: 19&lt;/div&gt;`)[0];\n",
" popup_3de3322fefe510d43316c12c9513d4e6.setContent(html_8464238f3f66d27f35c25aa2bd214c78);\n",
" \n",
" \n",
"\n",
" marker_7191d0497dcc99b03ff7c3f59679747c.bindPopup(popup_3de3322fefe510d43316c12c9513d4e6)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_75c75b6cfa732649e445d54d1e161c8b = L.marker(\n",
" [59.60990049999999, 16.5448091],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_84eabf133a0d10da2696b253076aa0e9 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_a355c0049a14ce002b9da64e7b136eb6 = $(`&lt;div id=&quot;html_a355c0049a14ce002b9da64e7b136eb6&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Västerås &lt;br&gt;Arbitrary Value: 22&lt;/div&gt;`)[0];\n",
" popup_84eabf133a0d10da2696b253076aa0e9.setContent(html_a355c0049a14ce002b9da64e7b136eb6);\n",
" \n",
" \n",
"\n",
" marker_75c75b6cfa732649e445d54d1e161c8b.bindPopup(popup_84eabf133a0d10da2696b253076aa0e9)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_b6ce490289d6e1779ee40836e3c04014 = L.marker(\n",
" [59.2752626, 15.2134105],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_78947e3c5793479d55cd407e77c25332 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_1d51b1fa5d90c064a580235d59857d7b = $(`&lt;div id=&quot;html_1d51b1fa5d90c064a580235d59857d7b&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Örebro &lt;br&gt;Arbitrary Value: 15&lt;/div&gt;`)[0];\n",
" popup_78947e3c5793479d55cd407e77c25332.setContent(html_1d51b1fa5d90c064a580235d59857d7b);\n",
" \n",
" \n",
"\n",
" marker_b6ce490289d6e1779ee40836e3c04014.bindPopup(popup_78947e3c5793479d55cd407e77c25332)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_3ca461804b9e5b15d8ba80bc4280327f = L.marker(\n",
" [58.41080700000001, 15.6213727],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_4e1feb2be8788cc3a924af6d7a9b96c8 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_3d3da58333ac4a523db6a03dbf9ef2a1 = $(`&lt;div id=&quot;html_3d3da58333ac4a523db6a03dbf9ef2a1&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Linköping &lt;br&gt;Arbitrary Value: 20&lt;/div&gt;`)[0];\n",
" popup_4e1feb2be8788cc3a924af6d7a9b96c8.setContent(html_3d3da58333ac4a523db6a03dbf9ef2a1);\n",
" \n",
" \n",
"\n",
" marker_3ca461804b9e5b15d8ba80bc4280327f.bindPopup(popup_4e1feb2be8788cc3a924af6d7a9b96c8)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_abf33fe6175cde4ec0d9999f2309fa10 = L.marker(\n",
" [56.0464674, 12.6945121],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_7044a1439a13b7a41649c597568f404e = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_b3530ba9838099fc6a8b3650f0f6c8a6 = $(`&lt;div id=&quot;html_b3530ba9838099fc6a8b3650f0f6c8a6&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Helsingborg &lt;br&gt;Arbitrary Value: 24&lt;/div&gt;`)[0];\n",
" popup_7044a1439a13b7a41649c597568f404e.setContent(html_b3530ba9838099fc6a8b3650f0f6c8a6);\n",
" \n",
" \n",
"\n",
" marker_abf33fe6175cde4ec0d9999f2309fa10.bindPopup(popup_7044a1439a13b7a41649c597568f404e)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_721460d2ced95f78a05ab5f8ca1933cf = L.marker(\n",
" [58.587745, 16.192421],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_c87f6cd21d4c973477a44a511dc53892 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_22c67a3aa58277e9f57fda16fd1924f7 = $(`&lt;div id=&quot;html_22c67a3aa58277e9f57fda16fd1924f7&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Norrköping &lt;br&gt;Arbitrary Value: 28&lt;/div&gt;`)[0];\n",
" popup_c87f6cd21d4c973477a44a511dc53892.setContent(html_22c67a3aa58277e9f57fda16fd1924f7);\n",
" \n",
" \n",
"\n",
" marker_721460d2ced95f78a05ab5f8ca1933cf.bindPopup(popup_c87f6cd21d4c973477a44a511dc53892)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_cc4d6557755d0d2f260717818f7fd037 = L.marker(\n",
" [57.78261370000001, 14.1617876],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_f6734f6a467530d62e03d3308c0415b0 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_781cc322c7661f0973ef5eaaeea8b0a9 = $(`&lt;div id=&quot;html_781cc322c7661f0973ef5eaaeea8b0a9&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Jönköping &lt;br&gt;Arbitrary Value: 17&lt;/div&gt;`)[0];\n",
" popup_f6734f6a467530d62e03d3308c0415b0.setContent(html_781cc322c7661f0973ef5eaaeea8b0a9);\n",
" \n",
" \n",
"\n",
" marker_cc4d6557755d0d2f260717818f7fd037.bindPopup(popup_f6734f6a467530d62e03d3308c0415b0)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_e89736780694b3507f534e75084dae5a = L.marker(\n",
" [55.7046601, 13.1910073],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_309f810c8fa1ded3fe755d1ab2f2a7cf = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_3d3a5de2c92387c8f623b55c71ad55d3 = $(`&lt;div id=&quot;html_3d3a5de2c92387c8f623b55c71ad55d3&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Lund &lt;br&gt;Arbitrary Value: 23&lt;/div&gt;`)[0];\n",
" popup_309f810c8fa1ded3fe755d1ab2f2a7cf.setContent(html_3d3a5de2c92387c8f623b55c71ad55d3);\n",
" \n",
" \n",
"\n",
" marker_e89736780694b3507f534e75084dae5a.bindPopup(popup_309f810c8fa1ded3fe755d1ab2f2a7cf)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_19316afbec307d92f4c9d952fe01ca18 = L.marker(\n",
" [63.8258471, 20.2630354],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_684270e79a4f3a1795690414bff4451c = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_f338859ca23c24c19d53c538b2c1a58b = $(`&lt;div id=&quot;html_f338859ca23c24c19d53c538b2c1a58b&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Umeå &lt;br&gt;Arbitrary Value: 10&lt;/div&gt;`)[0];\n",
" popup_684270e79a4f3a1795690414bff4451c.setContent(html_f338859ca23c24c19d53c538b2c1a58b);\n",
" \n",
" \n",
"\n",
" marker_19316afbec307d92f4c9d952fe01ca18.bindPopup(popup_684270e79a4f3a1795690414bff4451c)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_c732ad6f91eff2373799ed487a1dd5e5 = L.marker(\n",
" [60.6748796, 17.1412726],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_33ab6a008770bd3be28dcee3771a4698 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_e1ef0068812a2c9d252ed4d016e7f9c7 = $(`&lt;div id=&quot;html_e1ef0068812a2c9d252ed4d016e7f9c7&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Gävle &lt;br&gt;Arbitrary Value: 18&lt;/div&gt;`)[0];\n",
" popup_33ab6a008770bd3be28dcee3771a4698.setContent(html_e1ef0068812a2c9d252ed4d016e7f9c7);\n",
" \n",
" \n",
"\n",
" marker_c732ad6f91eff2373799ed487a1dd5e5.bindPopup(popup_33ab6a008770bd3be28dcee3771a4698)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_9d1da1e41fe60c3711d193c4b773d025 = L.marker(\n",
" [57.72103500000001, 12.939819],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_2210341247e2860486be6f5f75012109 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_56fdd9b6f6291d92352d6537e58cc8d2 = $(`&lt;div id=&quot;html_56fdd9b6f6291d92352d6537e58cc8d2&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Borås &lt;br&gt;Arbitrary Value: 14&lt;/div&gt;`)[0];\n",
" popup_2210341247e2860486be6f5f75012109.setContent(html_56fdd9b6f6291d92352d6537e58cc8d2);\n",
" \n",
" \n",
"\n",
" marker_9d1da1e41fe60c3711d193c4b773d025.bindPopup(popup_2210341247e2860486be6f5f75012109)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_9439c5c8d6afc76016da6f702390864e = L.marker(\n",
" [59.37124859999999, 16.5098045],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_4f217ddd0c2d221e3661d825209baf01 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_3f775f4fd4919783203c47b3019f4630 = $(`&lt;div id=&quot;html_3f775f4fd4919783203c47b3019f4630&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Eskilstuna &lt;br&gt;Arbitrary Value: 16&lt;/div&gt;`)[0];\n",
" popup_4f217ddd0c2d221e3661d825209baf01.setContent(html_3f775f4fd4919783203c47b3019f4630);\n",
" \n",
" \n",
"\n",
" marker_9439c5c8d6afc76016da6f702390864e.bindPopup(popup_4f217ddd0c2d221e3661d825209baf01)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_6069a735c587625c265fd865b153d433 = L.marker(\n",
" [59.197762, 17.6201942],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_502e1baf1b6bfd4ce496017e874d4867 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_db33a6851e1cbc943878e5a925b8c1bf = $(`&lt;div id=&quot;html_db33a6851e1cbc943878e5a925b8c1bf&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Södertälje &lt;br&gt;Arbitrary Value: 13&lt;/div&gt;`)[0];\n",
" popup_502e1baf1b6bfd4ce496017e874d4867.setContent(html_db33a6851e1cbc943878e5a925b8c1bf);\n",
" \n",
" \n",
"\n",
" marker_6069a735c587625c265fd865b153d433.bindPopup(popup_502e1baf1b6bfd4ce496017e874d4867)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_ef0d420980471d7d76653f74ae35b2e3 = L.marker(\n",
" [59.4021806, 13.5114977],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_c6e01a133d20b9da7f368db1e61e3b56 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_5d81288e5600957f5e6157b15541128b = $(`&lt;div id=&quot;html_5d81288e5600957f5e6157b15541128b&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Karlstad &lt;br&gt;Arbitrary Value: 21&lt;/div&gt;`)[0];\n",
" popup_c6e01a133d20b9da7f368db1e61e3b56.setContent(html_5d81288e5600957f5e6157b15541128b);\n",
" \n",
" \n",
"\n",
" marker_ef0d420980471d7d76653f74ae35b2e3.bindPopup(popup_c6e01a133d20b9da7f368db1e61e3b56)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_9481154cfe7b1360ba900e47584cdfb4 = L.marker(\n",
" [59.4419, 18.0703299],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_74bee800522a8b8ddb65315972355009 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_b221290a7ac258268ae5c0ae3bd2e2e6 = $(`&lt;div id=&quot;html_b221290a7ac258268ae5c0ae3bd2e2e6&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Täby &lt;br&gt;Arbitrary Value: 29&lt;/div&gt;`)[0];\n",
" popup_74bee800522a8b8ddb65315972355009.setContent(html_b221290a7ac258268ae5c0ae3bd2e2e6);\n",
" \n",
" \n",
"\n",
" marker_9481154cfe7b1360ba900e47584cdfb4.bindPopup(popup_74bee800522a8b8ddb65315972355009)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_7133f405246b83ced5b27fd381b41d82 = L.marker(\n",
" [56.8790044, 14.8058522],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_6f7ec17b754a2d9d628e606c8a474e21 = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_27c2422c45f6f729446366d6c54f05da = $(`&lt;div id=&quot;html_27c2422c45f6f729446366d6c54f05da&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Växjö &lt;br&gt;Arbitrary Value: 11&lt;/div&gt;`)[0];\n",
" popup_6f7ec17b754a2d9d628e606c8a474e21.setContent(html_27c2422c45f6f729446366d6c54f05da);\n",
" \n",
" \n",
"\n",
" marker_7133f405246b83ced5b27fd381b41d82.bindPopup(popup_6f7ec17b754a2d9d628e606c8a474e21)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" var marker_047fbcaa59cd07b8b81a5bea555a4504 = L.marker(\n",
" [56.6743748, 12.8577884],\n",
" {}\n",
" ).addTo(map_55a6f4f8a1b66703984981c5543b4276);\n",
" \n",
" \n",
" var popup_257924e079177e084f969e63db6b655b = L.popup({&quot;maxWidth&quot;: &quot;100%&quot;});\n",
"\n",
" \n",
" \n",
" var html_28ee77ce6cb7f54dae08d4bdf4bf7242 = $(`&lt;div id=&quot;html_28ee77ce6cb7f54dae08d4bdf4bf7242&quot; style=&quot;width: 100.0%; height: 100.0%;&quot;&gt; Halmstad &lt;br&gt;Arbitrary Value: 26&lt;/div&gt;`)[0];\n",
" popup_257924e079177e084f969e63db6b655b.setContent(html_28ee77ce6cb7f54dae08d4bdf4bf7242);\n",
" \n",
" \n",
"\n",
" marker_047fbcaa59cd07b8b81a5bea555a4504.bindPopup(popup_257924e079177e084f969e63db6b655b)\n",
" ;\n",
"\n",
" \n",
" \n",
" \n",
" map_55a6f4f8a1b66703984981c5543b4276.fitBounds(\n",
" [[59.32932349999999, 18.0685808], [57.70887, 11.97456], [55.604981, 13.003822], [59.85856380000001, 17.6389267], [59.60990049999999, 16.5448091], [59.2752626, 15.2134105], [58.41080700000001, 15.6213727], [56.0464674, 12.6945121], [58.587745, 16.192421], [57.78261370000001, 14.1617876], [55.7046601, 13.1910073], [63.8258471, 20.2630354], [60.6748796, 17.1412726], [57.72103500000001, 12.939819], [59.37124859999999, 16.5098045], [59.197762, 17.6201942], [59.4021806, 13.5114977], [59.4419, 18.0703299], [56.8790044, 14.8058522], [56.6743748, 12.8577884]],\n",
" {}\n",
" );\n",
" \n",
"&lt;/script&gt;\n",
"&lt;/html&gt;\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
]
},
"metadata": {},
"execution_count": 6
}
]
},
{
"cell_type": "markdown",
"source": [
"## Save Geocoded Data\n",
"\n",
"Finally, let's save our geocoded data to a new CSV file.\n"
],
"metadata": {
"id": "fNfkHolvGoAB"
}
},
{
"cell_type": "code",
"source": [
"# Save the DataFrame with the geocoded data to a new CSV file\n",
"output_filename = 'geocoded_locations.csv' # Replace with your desired output filename.\n",
"df.to_csv(output_filename, index=False)\n",
"\n",
"print(f'The geocoded data has been saved to {output_filename}')\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "eGB30YZGGoyd",
"outputId": "7216627e-afaf-4b09-f0eb-3e3907f957ab"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"The geocoded data has been saved to geocoded_locations.csv\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment