Skip to content

Instantly share code, notes, and snippets.

@gustamo
Created June 25, 2020 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustamo/d6ab4a09522e033f8e31a936bd14410e to your computer and use it in GitHub Desktop.
Save gustamo/d6ab4a09522e033f8e31a936bd14410e to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://en.wikipedia.org/wiki/The_Accidental_Tourist_(film)\">\n",
"<img src = \"https://images-na.ssl-images-amazon.com/images/I/91hXwldu4lL._RI_.jpg\" width = 400> </a>\n",
"\n",
"<h1 align=center><font size = 5>The Accidental Tourist Reccomendation System</font></h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1 align=center><font size = 3>This notebook was made for the travelers that live in NY and want to visit Toronto. Even far from their neighborhoods, they want to have the same conveniences they have in the neighborhood they live. They don't want to be badly surprised with having no venues around that they are not used to. So the user will pick the neighborhood he lives in NY from a list, and then the algorithm will find the similar neighborhoods in Toronto. </font></h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, we import all the libraries we need:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/jupyterlab/conda/envs/python\n",
"\n",
" added / updated specs:\n",
" - geopy\n",
"\n",
"\n",
"The following packages will be downloaded:\n",
"\n",
" package | build\n",
" ---------------------------|-----------------\n",
" ca-certificates-2020.6.20 | hecda079_0 145 KB conda-forge\n",
" certifi-2020.6.20 | py36h9f0ad1d_0 151 KB conda-forge\n",
" geographiclib-1.50 | py_0 34 KB conda-forge\n",
" geopy-1.22.0 | pyh9f0ad1d_0 63 KB conda-forge\n",
" ------------------------------------------------------------\n",
" Total: 393 KB\n",
"\n",
"The following NEW packages will be INSTALLED:\n",
"\n",
" geographiclib conda-forge/noarch::geographiclib-1.50-py_0\n",
" geopy conda-forge/noarch::geopy-1.22.0-pyh9f0ad1d_0\n",
"\n",
"The following packages will be UPDATED:\n",
"\n",
" ca-certificates 2020.4.5.2-hecda079_0 --> 2020.6.20-hecda079_0\n",
" certifi 2020.4.5.2-py36h9f0ad1d_0 --> 2020.6.20-py36h9f0ad1d_0\n",
"\n",
"\n",
"\n",
"Downloading and Extracting Packages\n",
"certifi-2020.6.20 | 151 KB | ##################################### | 100% \n",
"geopy-1.22.0 | 63 KB | ##################################### | 100% \n",
"ca-certificates-2020 | 145 KB | ##################################### | 100% \n",
"geographiclib-1.50 | 34 KB | ##################################### | 100% \n",
"Preparing transaction: done\n",
"Verifying transaction: done\n",
"Executing transaction: done\n",
"Collecting package metadata (current_repodata.json): done\n",
"Solving environment: failed with initial frozen solve. Retrying with flexible solve.\n",
"Collecting package metadata (repodata.json): done\n",
"Solving environment: done\n",
"\n",
"## Package Plan ##\n",
"\n",
" environment location: /home/jupyterlab/conda/envs/python\n",
"\n",
" added / updated specs:\n",
" - folium=0.5.0\n",
"\n",
"\n",
"The following packages will be downloaded:\n",
"\n",
" package | build\n",
" ---------------------------|-----------------\n",
" altair-4.1.0 | py_1 614 KB conda-forge\n",
" branca-0.4.1 | py_0 26 KB conda-forge\n",
" brotlipy-0.7.0 |py36h8c4c3a4_1000 346 KB conda-forge\n",
" chardet-3.0.4 |py36h9f0ad1d_1006 188 KB conda-forge\n",
" cryptography-2.9.2 | py36h45558ae_0 613 KB conda-forge\n",
" folium-0.5.0 | py_0 45 KB conda-forge\n",
" pandas-1.0.5 | py36h830a2c2_0 10.1 MB conda-forge\n",
" pysocks-1.7.1 | py36h9f0ad1d_1 27 KB conda-forge\n",
" requests-2.24.0 | pyh9f0ad1d_0 47 KB conda-forge\n",
" toolz-0.10.0 | py_0 46 KB conda-forge\n",
" vincent-0.4.4 | py_1 28 KB conda-forge\n",
" ------------------------------------------------------------\n",
" Total: 12.0 MB\n",
"\n",
"The following NEW packages will be INSTALLED:\n",
"\n",
" altair conda-forge/noarch::altair-4.1.0-py_1\n",
" attrs conda-forge/noarch::attrs-19.3.0-py_0\n",
" branca conda-forge/noarch::branca-0.4.1-py_0\n",
" brotlipy conda-forge/linux-64::brotlipy-0.7.0-py36h8c4c3a4_1000\n",
" chardet conda-forge/linux-64::chardet-3.0.4-py36h9f0ad1d_1006\n",
" cryptography conda-forge/linux-64::cryptography-2.9.2-py36h45558ae_0\n",
" entrypoints conda-forge/linux-64::entrypoints-0.3-py36h9f0ad1d_1001\n",
" folium conda-forge/noarch::folium-0.5.0-py_0\n",
" idna conda-forge/noarch::idna-2.9-py_1\n",
" importlib_metadata conda-forge/noarch::importlib_metadata-1.6.1-0\n",
" jinja2 conda-forge/noarch::jinja2-2.11.2-pyh9f0ad1d_0\n",
" jsonschema conda-forge/linux-64::jsonschema-3.2.0-py36h9f0ad1d_1\n",
" markupsafe conda-forge/linux-64::markupsafe-1.1.1-py36h8c4c3a4_1\n",
" pandas conda-forge/linux-64::pandas-1.0.5-py36h830a2c2_0\n",
" pyopenssl conda-forge/noarch::pyopenssl-19.1.0-py_1\n",
" pyrsistent conda-forge/linux-64::pyrsistent-0.16.0-py36h8c4c3a4_0\n",
" pysocks conda-forge/linux-64::pysocks-1.7.1-py36h9f0ad1d_1\n",
" pytz conda-forge/noarch::pytz-2020.1-pyh9f0ad1d_0\n",
" requests conda-forge/noarch::requests-2.24.0-pyh9f0ad1d_0\n",
" toolz conda-forge/noarch::toolz-0.10.0-py_0\n",
" urllib3 conda-forge/noarch::urllib3-1.25.9-py_0\n",
" vincent conda-forge/noarch::vincent-0.4.4-py_1\n",
"\n",
"\n",
"\n",
"Downloading and Extracting Packages\n",
"pysocks-1.7.1 | 27 KB | ##################################### | 100% \n",
"toolz-0.10.0 | 46 KB | ##################################### | 100% \n",
"chardet-3.0.4 | 188 KB | ##################################### | 100% \n",
"folium-0.5.0 | 45 KB | ##################################### | 100% \n",
"branca-0.4.1 | 26 KB | ##################################### | 100% \n",
"cryptography-2.9.2 | 613 KB | ##################################### | 100% \n",
"brotlipy-0.7.0 | 346 KB | ##################################### | 100% \n",
"altair-4.1.0 | 614 KB | ##################################### | 100% \n",
"requests-2.24.0 | 47 KB | ##################################### | 100% \n",
"pandas-1.0.5 | 10.1 MB | ##################################### | 100% \n",
"vincent-0.4.4 | 28 KB | ##################################### | 100% \n",
"Preparing transaction: done\n",
"Verifying transaction: done\n",
"Executing transaction: done\n"
]
}
],
"source": [
"import numpy as np # library to handle data in a vectorized manner\n",
"\n",
"import pandas as pd # library for data analsysis\n",
"pd.set_option('display.max_columns', None)\n",
"pd.set_option('display.max_rows', None)\n",
"\n",
"import json # library to handle JSON files\n",
"\n",
"!conda install -c conda-forge geopy --yes # uncomment this line if you haven't completed the Foursquare API lab\n",
"from geopy.geocoders import Nominatim # convert an address into latitude and longitude values\n",
"\n",
"import requests # library to handle requests\n",
"from pandas.io.json import json_normalize # tranform JSON file into a pandas dataframe\n",
"\n",
"# Matplotlib and associated plotting modules\n",
"import matplotlib.cm as cm\n",
"import matplotlib.colors as colors\n",
"\n",
"# import k-means from clustering stage\n",
"from sklearn.cluster import KMeans\n",
"\n",
"!conda install -c conda-forge folium=0.5.0 --yes # uncomment this line if you haven't completed the Foursquare API lab\n",
"import folium # map rendering library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: ipywidgets in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (7.4.2)\n",
"Requirement already satisfied: ipython>=4.0.0; python_version >= \"3.3\" in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipywidgets) (7.15.0)\n",
"Requirement already satisfied: ipykernel>=4.5.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipywidgets) (5.3.0)\n",
"Requirement already satisfied: traitlets>=4.3.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipywidgets) (4.3.3)\n",
"Requirement already satisfied: nbformat>=4.2.0 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipywidgets) (5.0.7)\n",
"Requirement already satisfied: widgetsnbextension~=3.4.0 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipywidgets) (3.4.2)\n",
"Requirement already satisfied: decorator in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (4.4.2)\n",
"Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (3.0.5)\n",
"Requirement already satisfied: backcall in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (0.2.0)\n",
"Requirement already satisfied: pexpect; sys_platform != \"win32\" in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (4.8.0)\n",
"Requirement already satisfied: pygments in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (2.6.1)\n",
"Requirement already satisfied: jedi>=0.10 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (0.17.0)\n",
"Requirement already satisfied: pickleshare in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (0.7.5)\n",
"Requirement already satisfied: setuptools>=18.5 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (47.1.1.post20200529)\n",
"Requirement already satisfied: tornado>=4.2 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipykernel>=4.5.1->ipywidgets) (6.0.4)\n",
"Requirement already satisfied: jupyter-client in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from ipykernel>=4.5.1->ipywidgets) (6.1.3)\n",
"Requirement already satisfied: six in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from traitlets>=4.3.1->ipywidgets) (1.15.0)\n",
"Requirement already satisfied: ipython-genutils in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from traitlets>=4.3.1->ipywidgets) (0.2.0)\n",
"Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbformat>=4.2.0->ipywidgets) (3.2.0)\n",
"Requirement already satisfied: jupyter-core in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbformat>=4.2.0->ipywidgets) (4.6.3)\n",
"Requirement already satisfied: notebook>=4.4.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from widgetsnbextension~=3.4.0->ipywidgets) (6.0.3)\n",
"Requirement already satisfied: wcwidth in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (0.2.4)\n",
"Requirement already satisfied: ptyprocess>=0.5 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from pexpect; sys_platform != \"win32\"->ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (0.6.0)\n",
"Requirement already satisfied: parso>=0.7.0 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jedi>=0.10->ipython>=4.0.0; python_version >= \"3.3\"->ipywidgets) (0.7.0)\n",
"Requirement already satisfied: pyzmq>=13 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets) (19.0.1)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets) (2.8.1)\n",
"Requirement already satisfied: attrs>=17.4.0 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets) (19.3.0)\n",
"Requirement already satisfied: importlib-metadata; python_version < \"3.8\" in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets) (1.6.1)\n",
"Requirement already satisfied: pyrsistent>=0.14.0 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets) (0.16.0)\n",
"Requirement already satisfied: jinja2 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (2.11.2)\n",
"Requirement already satisfied: nbconvert in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (5.6.1)\n",
"Requirement already satisfied: terminado>=0.8.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.8.3)\n",
"Requirement already satisfied: Send2Trash in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (1.5.0)\n",
"Requirement already satisfied: prometheus-client in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.8.0)\n",
"Requirement already satisfied: zipp>=0.5 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from importlib-metadata; python_version < \"3.8\"->jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets) (3.1.0)\n",
"Requirement already satisfied: MarkupSafe>=0.23 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from jinja2->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (1.1.1)\n",
"Requirement already satisfied: entrypoints>=0.2.2 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.3)\n",
"Requirement already satisfied: bleach in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (1.5.0)\n",
"Requirement already satisfied: testpath in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.4.4)\n",
"Requirement already satisfied: pandocfilters>=1.4.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (1.4.2)\n",
"Requirement already satisfied: mistune<2,>=0.8.1 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.8.4)\n",
"Requirement already satisfied: defusedxml in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.6.0)\n",
"Requirement already satisfied: html5lib!=0.9999,!=0.99999,<0.99999999,>=0.999 in /home/jupyterlab/conda/envs/python/lib/python3.6/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.4.0->ipywidgets) (0.9999999)\n",
"Enabling notebook extension jupyter-js-widgets/extension...\n",
" - Validating: \u001b[32mOK\u001b[0m\n"
]
}
],
"source": [
"!pip install ipywidgets\n",
"!jupyter nbextension enable --py widgetsnbextension\n",
"import ipywidgets as widgets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we start importing the data from Toronto:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shape of Dataframe: (183, 3)\n"
]
},
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighborhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M1A</td>\n",
" <td>Not assigned</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M2A</td>\n",
" <td>Not assigned</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M4A</td>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Borough Neighborhood\n",
"0 M1A Not assigned NaN\n",
"1 M2A Not assigned NaN\n",
"2 M3A North York Parkwoods\n",
"3 M4A North York Victoria Village\n",
"4 M5A Downtown Toronto Regent Park / Harbourfront"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## I've copied the table of neighborhoods from Wikipedia, and saved it to a CSV file.\n",
"## Let's put it to a Pandas dataframe:\n",
"wiki_toronto_neighborhoods_raw = pd.read_csv('Wiki_Toronto_Neighborhoods.csv')\n",
"print('Shape of Dataframe: ',wiki_toronto_neighborhoods_raw.shape)\n",
"\n",
"## Rename column so it gets exactly like instructed by Alex:\n",
"wiki_toronto_neighborhoods_raw.rename(columns={\"Postal code\": \"Postalcode\"}, inplace=True)\n",
"wiki_toronto_neighborhoods_raw.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Shape of Dataframe after removing \"Not assigned\" Boroughs: (106, 3)\n",
"Shape of Dataframe after removing NaN values: (103, 3)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/ipykernel_launcher.py:7: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" import sys\n"
]
},
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighborhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M4A</td>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M7A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Borough Neighborhood\n",
"0 M3A North York Parkwoods\n",
"1 M4A North York Victoria Village\n",
"2 M5A Downtown Toronto Regent Park / Harbourfront\n",
"3 M6A North York Lawrence Manor / Lawrence Heights\n",
"4 M7A Downtown Toronto Queen's Park / Ontario Provincial Government"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Remove the 'Not assigned' Boroughs\n",
"condition = wiki_toronto_neighborhoods_raw['Borough'] != 'Not assigned'\n",
"Toronto_Neighb = wiki_toronto_neighborhoods_raw[condition]\n",
"print('Shape of Dataframe after removing \"Not assigned\" Boroughs: ',Toronto_Neighb.shape)\n",
"\n",
"## Also, remove the records with Nan in any columns, to clean the table (there were only 3)\n",
"Toronto_Neighb.dropna(how='any', inplace = True)\n",
"Toronto_Neighb.reset_index(drop=True, inplace=True)\n",
"print('Shape of Dataframe after removing NaN values: ',Toronto_Neighb.shape)\n",
"Toronto_Neighb.head()\n",
"\n",
"## There is no need to aggregate records (as asked by Alex) since the Wikipedia page is updated\n",
"## So this line keeps commentend:\n",
"## Toronto_Neighb = Toronto_Neighb.groupby(level=['Postalcode'], sort=False).agg( ','.join)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighborhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>M1S</td>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" </tr>\n",
" <tr>\n",
" <th>93</th>\n",
" <td>M8W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood / Long Branch</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>M3H</td>\n",
" <td>North York</td>\n",
" <td>Bathurst Manor / Wilson Heights / Downsview North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39</th>\n",
" <td>M2K</td>\n",
" <td>North York</td>\n",
" <td>Bayview Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>55</th>\n",
" <td>M5M</td>\n",
" <td>North York</td>\n",
" <td>Bedford Park / Lawrence Manor East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>M5E</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Berczy Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>58</th>\n",
" <td>M1N</td>\n",
" <td>Scarborough</td>\n",
" <td>Birch Cliff / Cliffside West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>M6K</td>\n",
" <td>West Toronto</td>\n",
" <td>Brockton / Parkdale Village / Exhibition Place</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>M7Y</td>\n",
" <td>East Toronto</td>\n",
" <td>Business reply mail Processing CentrE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>87</th>\n",
" <td>M5V</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>CN Tower / King and Spadina / Railway Lands / ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>M6E</td>\n",
" <td>York</td>\n",
" <td>Caledonia-Fairbanks</td>\n",
" </tr>\n",
" <tr>\n",
" <th>76</th>\n",
" <td>M7R</td>\n",
" <td>Mississauga</td>\n",
" <td>Canada Post Gateway Processing Centre</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>M1H</td>\n",
" <td>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>M5G</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Central Bay Street</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>M6G</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Christie</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
" <td>M4Y</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Church and Wellesley</td>\n",
" </tr>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>M1T</td>\n",
" <td>Scarborough</td>\n",
" <td>Clarks Corners / Tam O'Shanter / Sullivan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>51</th>\n",
" <td>M1M</td>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside / Cliffcrest / Scarborough Village West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>48</th>\n",
" <td>M5L</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Commerce Court / Victoria Hotel</td>\n",
" </tr>\n",
" <tr>\n",
" <th>79</th>\n",
" <td>M4S</td>\n",
" <td>Central Toronto</td>\n",
" <td>Davisville</td>\n",
" </tr>\n",
" <tr>\n",
" <th>67</th>\n",
" <td>M4P</td>\n",
" <td>Central Toronto</td>\n",
" <td>Davisville North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>56</th>\n",
" <td>M6M</td>\n",
" <td>York</td>\n",
" <td>Del Ray / Mount Dennis / Keelsdale and Silvert...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>M3B</td>\n",
" <td>North York</td>\n",
" <td>Don Mills</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>M3C</td>\n",
" <td>North York</td>\n",
" <td>Don Mills</td>\n",
" </tr>\n",
" <tr>\n",
" <th>65</th>\n",
" <td>M1P</td>\n",
" <td>Scarborough</td>\n",
" <td>Dorset Park / Wexford Heights / Scarborough To...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>M3K</td>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>M3L</td>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" </tr>\n",
" <tr>\n",
" <th>60</th>\n",
" <td>M3N</td>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" </tr>\n",
" <tr>\n",
" <th>53</th>\n",
" <td>M3M</td>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>M6H</td>\n",
" <td>West Toronto</td>\n",
" <td>Dufferin / Dovercourt Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>M4J</td>\n",
" <td>East York</td>\n",
" <td>East Toronto</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>M9C</td>\n",
" <td>Etobicoke</td>\n",
" <td>Eringate / Bloordale Gardens / Old Burnhamthor...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>M2J</td>\n",
" <td>North York</td>\n",
" <td>Fairview / Henry Farm / Oriole</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>M5X</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>First Canadian Place / Underground city</td>\n",
" </tr>\n",
" <tr>\n",
" <th>68</th>\n",
" <td>M5P</td>\n",
" <td>Central Toronto</td>\n",
" <td>Forest Hill North &amp; West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>M5B</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Garden District-Ryerson</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>M6B</td>\n",
" <td>North York</td>\n",
" <td>Glencairn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>M1L</td>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile / Clairlea / Oakridge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>M1E</td>\n",
" <td>Scarborough</td>\n",
" <td>Guildwood / Morningside / West Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>M5J</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Harbourfront East / Union Station / Toronto Is...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>69</th>\n",
" <td>M6P</td>\n",
" <td>West Toronto</td>\n",
" <td>High Park / The Junction South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>M2H</td>\n",
" <td>North York</td>\n",
" <td>Hillcrest Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>M9L</td>\n",
" <td>North York</td>\n",
" <td>Humber Summit</td>\n",
" </tr>\n",
" <tr>\n",
" <th>57</th>\n",
" <td>M9M</td>\n",
" <td>North York</td>\n",
" <td>Humberlea / Emery</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>M6C</td>\n",
" <td>York</td>\n",
" <td>Humewood-Cedarvale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47</th>\n",
" <td>M4L</td>\n",
" <td>East Toronto</td>\n",
" <td>India Bazaar / The Beaches West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>M9A</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>M1K</td>\n",
" <td>Scarborough</td>\n",
" <td>Kennedy Park / Ionview / East Birchmount Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>M5T</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Kensington Market / Chinatown / Grange Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>77</th>\n",
" <td>M9R</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsview Village / St. Phillips / Martin Grov...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>61</th>\n",
" <td>M4N</td>\n",
" <td>Central Toronto</td>\n",
" <td>Lawrence Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>M4G</td>\n",
" <td>East York</td>\n",
" <td>Leaside</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>M6J</td>\n",
" <td>West Toronto</td>\n",
" <td>Little Portugal / Trinity</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Malvern / Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>M1V</td>\n",
" <td>Scarborough</td>\n",
" <td>Milliken / Agincourt North / Steeles East / L'...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico NW / The Queensway West / South of Bloo...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>M4T</td>\n",
" <td>Central Toronto</td>\n",
" <td>Moore Park / Summerhill East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>88</th>\n",
" <td>M8V</td>\n",
" <td>Etobicoke</td>\n",
" <td>New Toronto / Mimico South / Humber Bay Shores</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49</th>\n",
" <td>M6L</td>\n",
" <td>North York</td>\n",
" <td>North Park / Maple Leaf Park / Upwood Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>73</th>\n",
" <td>M4R</td>\n",
" <td>Central Toronto</td>\n",
" <td>North Toronto West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>94</th>\n",
" <td>M9W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>M3J</td>\n",
" <td>North York</td>\n",
" <td>Northwood Park / York University</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Old Mill South / King's Mill Park / Sunnylea /...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75</th>\n",
" <td>M6R</td>\n",
" <td>West Toronto</td>\n",
" <td>Parkdale / Roncesvalles</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>M4B</td>\n",
" <td>East York</td>\n",
" <td>Parkview Hill / Woodbine Gardens</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M7A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>M5H</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Richmond / Adelaide / King</td>\n",
" </tr>\n",
" <tr>\n",
" <th>91</th>\n",
" <td>M4W</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Rosedale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>62</th>\n",
" <td>M5N</td>\n",
" <td>Central Toronto</td>\n",
" <td>Roselawn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Rouge Hill / Port Union / Highland Creek</td>\n",
" </tr>\n",
" <tr>\n",
" <th>81</th>\n",
" <td>M6S</td>\n",
" <td>West Toronto</td>\n",
" <td>Runnymede / Swansea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>63</th>\n",
" <td>M6N</td>\n",
" <td>York</td>\n",
" <td>Runnymede / The Junction North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>M1J</td>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>89</th>\n",
" <td>M9V</td>\n",
" <td>Etobicoke</td>\n",
" <td>South Steeles / Silverstone / Humbergate / Jam...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>M5C</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>St. James Town</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>M4X</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>St. James Town / Cabbagetown</td>\n",
" </tr>\n",
" <tr>\n",
" <th>90</th>\n",
" <td>M1W</td>\n",
" <td>Scarborough</td>\n",
" <td>Steeles West / L'Amoreaux West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>M5W</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Stn A PO Boxes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
" <td>M4M</td>\n",
" <td>East Toronto</td>\n",
" <td>Studio District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>86</th>\n",
" <td>M4V</td>\n",
" <td>Central Toronto</td>\n",
" <td>Summerhill West / Rathnelly / South Hill / For...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>M5R</td>\n",
" <td>Central Toronto</td>\n",
" <td>The Annex / North Midtown / Yorkville</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>M4E</td>\n",
" <td>East Toronto</td>\n",
" <td>The Beaches</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>M4K</td>\n",
" <td>East Toronto</td>\n",
" <td>The Danforth West / Riverdale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>M8X</td>\n",
" <td>Etobicoke</td>\n",
" <td>The Kingsway / Montgomery Road / Old Mill North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>M4H</td>\n",
" <td>East York</td>\n",
" <td>Thorncliffe Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>42</th>\n",
" <td>M5K</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Toronto Dominion Centre / Design Exchange</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>M5S</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>University of Toronto / Harbord</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>M1X</td>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M4A</td>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>West Deane Park / Princess Gardens / Martin Gr...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>70</th>\n",
" <td>M9P</td>\n",
" <td>Etobicoke</td>\n",
" <td>Westmount</td>\n",
" </tr>\n",
" <tr>\n",
" <th>64</th>\n",
" <td>M9N</td>\n",
" <td>York</td>\n",
" <td>Weston</td>\n",
" </tr>\n",
" <tr>\n",
" <th>71</th>\n",
" <td>M1R</td>\n",
" <td>Scarborough</td>\n",
" <td>Wexford / Maryvale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>72</th>\n",
" <td>M2R</td>\n",
" <td>North York</td>\n",
" <td>Willowdale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>59</th>\n",
" <td>M2N</td>\n",
" <td>North York</td>\n",
" <td>Willowdale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>52</th>\n",
" <td>M2M</td>\n",
" <td>North York</td>\n",
" <td>Willowdale / Newtonbrook</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>M1G</td>\n",
" <td>Scarborough</td>\n",
" <td>Woburn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>M4C</td>\n",
" <td>East York</td>\n",
" <td>Woodbine Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>M2L</td>\n",
" <td>North York</td>\n",
" <td>York Mills / Silver Hills</td>\n",
" </tr>\n",
" <tr>\n",
" <th>66</th>\n",
" <td>M2P</td>\n",
" <td>North York</td>\n",
" <td>York Mills West</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Borough \\\n",
"78 M1S Scarborough \n",
"93 M8W Etobicoke \n",
"28 M3H North York \n",
"39 M2K North York \n",
"55 M5M North York \n",
"20 M5E Downtown Toronto \n",
"58 M1N Scarborough \n",
"43 M6K West Toronto \n",
"100 M7Y East Toronto \n",
"87 M5V Downtown Toronto \n",
"21 M6E York \n",
"76 M7R Mississauga \n",
"26 M1H Scarborough \n",
"24 M5G Downtown Toronto \n",
"25 M6G Downtown Toronto \n",
"99 M4Y Downtown Toronto \n",
"82 M1T Scarborough \n",
"51 M1M Scarborough \n",
"48 M5L Downtown Toronto \n",
"79 M4S Central Toronto \n",
"67 M4P Central Toronto \n",
"56 M6M York \n",
"7 M3B North York \n",
"13 M3C North York \n",
"65 M1P Scarborough \n",
"40 M3K North York \n",
"46 M3L North York \n",
"60 M3N North York \n",
"53 M3M North York \n",
"31 M6H West Toronto \n",
"35 M4J East York \n",
"17 M9C Etobicoke \n",
"33 M2J North York \n",
"97 M5X Downtown Toronto \n",
"68 M5P Central Toronto \n",
"9 M5B Downtown Toronto \n",
"10 M6B North York \n",
"44 M1L Scarborough \n",
"18 M1E Scarborough \n",
"36 M5J Downtown Toronto \n",
"69 M6P West Toronto \n",
"27 M2H North York \n",
"50 M9L North York \n",
"57 M9M North York \n",
"16 M6C York \n",
"47 M4L East Toronto \n",
"5 M9A Etobicoke \n",
"38 M1K Scarborough \n",
"84 M5T Downtown Toronto \n",
"77 M9R Etobicoke \n",
"3 M6A North York \n",
"61 M4N Central Toronto \n",
"23 M4G East York \n",
"37 M6J West Toronto \n",
"6 M1B Scarborough \n",
"85 M1V Scarborough \n",
"102 M8Z Etobicoke \n",
"83 M4T Central Toronto \n",
"88 M8V Etobicoke \n",
"49 M6L North York \n",
"73 M4R Central Toronto \n",
"94 M9W Etobicoke \n",
"34 M3J North York \n",
"101 M8Y Etobicoke \n",
"75 M6R West Toronto \n",
"8 M4B East York \n",
"0 M3A North York \n",
"4 M7A Downtown Toronto \n",
"2 M5A Downtown Toronto \n",
"30 M5H Downtown Toronto \n",
"91 M4W Downtown Toronto \n",
"62 M5N Central Toronto \n",
"12 M1C Scarborough \n",
"81 M6S West Toronto \n",
"63 M6N York \n",
"32 M1J Scarborough \n",
"89 M9V Etobicoke \n",
"15 M5C Downtown Toronto \n",
"96 M4X Downtown Toronto \n",
"90 M1W Scarborough \n",
"92 M5W Downtown Toronto \n",
"54 M4M East Toronto \n",
"86 M4V Central Toronto \n",
"74 M5R Central Toronto \n",
"19 M4E East Toronto \n",
"41 M4K East Toronto \n",
"98 M8X Etobicoke \n",
"29 M4H East York \n",
"42 M5K Downtown Toronto \n",
"80 M5S Downtown Toronto \n",
"95 M1X Scarborough \n",
"1 M4A North York \n",
"11 M9B Etobicoke \n",
"70 M9P Etobicoke \n",
"64 M9N York \n",
"71 M1R Scarborough \n",
"72 M2R North York \n",
"59 M2N North York \n",
"52 M2M North York \n",
"22 M1G Scarborough \n",
"14 M4C East York \n",
"45 M2L North York \n",
"66 M2P North York \n",
"\n",
" Neighborhood \n",
"78 Agincourt \n",
"93 Alderwood / Long Branch \n",
"28 Bathurst Manor / Wilson Heights / Downsview North \n",
"39 Bayview Village \n",
"55 Bedford Park / Lawrence Manor East \n",
"20 Berczy Park \n",
"58 Birch Cliff / Cliffside West \n",
"43 Brockton / Parkdale Village / Exhibition Place \n",
"100 Business reply mail Processing CentrE \n",
"87 CN Tower / King and Spadina / Railway Lands / ... \n",
"21 Caledonia-Fairbanks \n",
"76 Canada Post Gateway Processing Centre \n",
"26 Cedarbrae \n",
"24 Central Bay Street \n",
"25 Christie \n",
"99 Church and Wellesley \n",
"82 Clarks Corners / Tam O'Shanter / Sullivan \n",
"51 Cliffside / Cliffcrest / Scarborough Village West \n",
"48 Commerce Court / Victoria Hotel \n",
"79 Davisville \n",
"67 Davisville North \n",
"56 Del Ray / Mount Dennis / Keelsdale and Silvert... \n",
"7 Don Mills \n",
"13 Don Mills \n",
"65 Dorset Park / Wexford Heights / Scarborough To... \n",
"40 Downsview \n",
"46 Downsview \n",
"60 Downsview \n",
"53 Downsview \n",
"31 Dufferin / Dovercourt Village \n",
"35 East Toronto \n",
"17 Eringate / Bloordale Gardens / Old Burnhamthor... \n",
"33 Fairview / Henry Farm / Oriole \n",
"97 First Canadian Place / Underground city \n",
"68 Forest Hill North & West \n",
"9 Garden District-Ryerson \n",
"10 Glencairn \n",
"44 Golden Mile / Clairlea / Oakridge \n",
"18 Guildwood / Morningside / West Hill \n",
"36 Harbourfront East / Union Station / Toronto Is... \n",
"69 High Park / The Junction South \n",
"27 Hillcrest Village \n",
"50 Humber Summit \n",
"57 Humberlea / Emery \n",
"16 Humewood-Cedarvale \n",
"47 India Bazaar / The Beaches West \n",
"5 Islington Avenue \n",
"38 Kennedy Park / Ionview / East Birchmount Park \n",
"84 Kensington Market / Chinatown / Grange Park \n",
"77 Kingsview Village / St. Phillips / Martin Grov... \n",
"3 Lawrence Manor / Lawrence Heights \n",
"61 Lawrence Park \n",
"23 Leaside \n",
"37 Little Portugal / Trinity \n",
"6 Malvern / Rouge \n",
"85 Milliken / Agincourt North / Steeles East / L'... \n",
"102 Mimico NW / The Queensway West / South of Bloo... \n",
"83 Moore Park / Summerhill East \n",
"88 New Toronto / Mimico South / Humber Bay Shores \n",
"49 North Park / Maple Leaf Park / Upwood Park \n",
"73 North Toronto West \n",
"94 Northwest \n",
"34 Northwood Park / York University \n",
"101 Old Mill South / King's Mill Park / Sunnylea /... \n",
"75 Parkdale / Roncesvalles \n",
"8 Parkview Hill / Woodbine Gardens \n",
"0 Parkwoods \n",
"4 Queen's Park / Ontario Provincial Government \n",
"2 Regent Park / Harbourfront \n",
"30 Richmond / Adelaide / King \n",
"91 Rosedale \n",
"62 Roselawn \n",
"12 Rouge Hill / Port Union / Highland Creek \n",
"81 Runnymede / Swansea \n",
"63 Runnymede / The Junction North \n",
"32 Scarborough Village \n",
"89 South Steeles / Silverstone / Humbergate / Jam... \n",
"15 St. James Town \n",
"96 St. James Town / Cabbagetown \n",
"90 Steeles West / L'Amoreaux West \n",
"92 Stn A PO Boxes \n",
"54 Studio District \n",
"86 Summerhill West / Rathnelly / South Hill / For... \n",
"74 The Annex / North Midtown / Yorkville \n",
"19 The Beaches \n",
"41 The Danforth West / Riverdale \n",
"98 The Kingsway / Montgomery Road / Old Mill North \n",
"29 Thorncliffe Park \n",
"42 Toronto Dominion Centre / Design Exchange \n",
"80 University of Toronto / Harbord \n",
"95 Upper Rouge \n",
"1 Victoria Village \n",
"11 West Deane Park / Princess Gardens / Martin Gr... \n",
"70 Westmount \n",
"64 Weston \n",
"71 Wexford / Maryvale \n",
"72 Willowdale \n",
"59 Willowdale \n",
"52 Willowdale / Newtonbrook \n",
"22 Woburn \n",
"14 Woodbine Heights \n",
"45 York Mills / Silver Hills \n",
"66 York Mills West "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Toronto_Neighb.sort_values('Neighborhood')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M1B</td>\n",
" <td>43.806686</td>\n",
" <td>-79.194353</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M1C</td>\n",
" <td>43.784535</td>\n",
" <td>-79.160497</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M1E</td>\n",
" <td>43.763573</td>\n",
" <td>-79.188711</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M1G</td>\n",
" <td>43.770992</td>\n",
" <td>-79.216917</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M1H</td>\n",
" <td>43.773136</td>\n",
" <td>-79.239476</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Latitude Longitude\n",
"0 M1B 43.806686 -79.194353\n",
"1 M1C 43.784535 -79.160497\n",
"2 M1E 43.763573 -79.188711\n",
"3 M1G 43.770992 -79.216917\n",
"4 M1H 43.773136 -79.239476"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Now let's get the coordinates from other table. I've decided to get directly from the CSV file\n",
"## So let's put it in this dataframe:\n",
"\n",
"coord = pd.read_csv('Geospatial_Coordinates.csv')\n",
"coord.rename(columns={\"Postal Code\": \"Postalcode\"}, inplace=True)\n",
"coord.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" \n",
"/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/ipykernel_launcher.py:3: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" This is separate from the ipykernel package so we can avoid doing imports until\n"
]
},
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M4A</td>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M7A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Borough Neighborhood \\\n",
"0 M3A North York Parkwoods \n",
"1 M4A North York Victoria Village \n",
"2 M5A Downtown Toronto Regent Park / Harbourfront \n",
"3 M6A North York Lawrence Manor / Lawrence Heights \n",
"4 M7A Downtown Toronto Queen's Park / Ontario Provincial Government \n",
"\n",
" Latitude Longitude \n",
"0 NaN NaN \n",
"1 NaN NaN \n",
"2 NaN NaN \n",
"3 NaN NaN \n",
"4 NaN NaN "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Now let's create two new columns to accomodate the geolocation data:\n",
"Toronto_Neighb['Latitude'] = np.nan\n",
"Toronto_Neighb['Longitude'] = np.nan\n",
"Toronto_Neighb.head()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"## We want to update the values of \"coord\" into \"Toronto_Neighb\"\n",
"## I will use the update method, so first I need to equalize the indexes of both dataframes\n",
"Toronto_Neighb.set_index('Postalcode', inplace=True)\n",
"coord.set_index('Postalcode', inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Postalcode</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>M3A</th>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M4A</th>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M5A</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6A</th>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7A</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood \\\n",
"Postalcode \n",
"M3A North York Parkwoods \n",
"M4A North York Victoria Village \n",
"M5A Downtown Toronto Regent Park / Harbourfront \n",
"M6A North York Lawrence Manor / Lawrence Heights \n",
"M7A Downtown Toronto Queen's Park / Ontario Provincial Government \n",
"\n",
" Latitude Longitude \n",
"Postalcode \n",
"M3A NaN NaN \n",
"M4A NaN NaN \n",
"M5A NaN NaN \n",
"M6A NaN NaN \n",
"M7A NaN NaN "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## As you can see, now the Postalcode is the index:\n",
"Toronto_Neighb.head()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Postalcode</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>M1B</th>\n",
" <td>43.806686</td>\n",
" <td>-79.194353</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1C</th>\n",
" <td>43.784535</td>\n",
" <td>-79.160497</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1E</th>\n",
" <td>43.763573</td>\n",
" <td>-79.188711</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1G</th>\n",
" <td>43.770992</td>\n",
" <td>-79.216917</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1H</th>\n",
" <td>43.773136</td>\n",
" <td>-79.239476</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Latitude Longitude\n",
"Postalcode \n",
"M1B 43.806686 -79.194353\n",
"M1C 43.784535 -79.160497\n",
"M1E 43.763573 -79.188711\n",
"M1G 43.770992 -79.216917\n",
"M1H 43.773136 -79.239476"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## ...as well as in the coord dataframe:\n",
"coord.head()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/pandas/core/frame.py:5732: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" self[col] = expressions.where(mask, this, that)\n"
]
}
],
"source": [
"## Now we can use the update method, which update the columns of same name, based on the index:\n",
"Toronto_Neighb.update(coord)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Postalcode</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>M3A</th>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>43.753259</td>\n",
" <td>-79.329656</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M4A</th>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>43.725882</td>\n",
" <td>-79.315572</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M5A</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>43.654260</td>\n",
" <td>-79.360636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6A</th>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>43.718518</td>\n",
" <td>-79.464763</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7A</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" <td>43.662301</td>\n",
" <td>-79.389494</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood \\\n",
"Postalcode \n",
"M3A North York Parkwoods \n",
"M4A North York Victoria Village \n",
"M5A Downtown Toronto Regent Park / Harbourfront \n",
"M6A North York Lawrence Manor / Lawrence Heights \n",
"M7A Downtown Toronto Queen's Park / Ontario Provincial Government \n",
"\n",
" Latitude Longitude \n",
"Postalcode \n",
"M3A 43.753259 -79.329656 \n",
"M4A 43.725882 -79.315572 \n",
"M5A 43.654260 -79.360636 \n",
"M6A 43.718518 -79.464763 \n",
"M7A 43.662301 -79.389494 "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Now let's check if Latitude and Longitude are completed:\n",
"Toronto_Neighb.head()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"## Let's reset the index so our main dataframe gets back to what it was:\n",
"Toronto_Neighb.reset_index(inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>43.753259</td>\n",
" <td>-79.329656</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M4A</td>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>43.725882</td>\n",
" <td>-79.315572</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>43.654260</td>\n",
" <td>-79.360636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>43.718518</td>\n",
" <td>-79.464763</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M7A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" <td>43.662301</td>\n",
" <td>-79.389494</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Borough Neighborhood \\\n",
"0 M3A North York Parkwoods \n",
"1 M4A North York Victoria Village \n",
"2 M5A Downtown Toronto Regent Park / Harbourfront \n",
"3 M6A North York Lawrence Manor / Lawrence Heights \n",
"4 M7A Downtown Toronto Queen's Park / Ontario Provincial Government \n",
"\n",
" Latitude Longitude \n",
"0 43.753259 -79.329656 \n",
"1 43.725882 -79.315572 \n",
"2 43.654260 -79.360636 \n",
"3 43.718518 -79.464763 \n",
"4 43.662301 -79.389494 "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Toronto_Neighb.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All set for Toronto! Now let's work on NY data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Neighborhood has a total of 5 boroughs and 306 neighborhoods. In order to segement the neighborhoods and explore them, we will essentially need a dataset that contains the 5 boroughs and the neighborhoods that exist in each borough as well as the the latitude and logitude coordinates of each neighborhood. \n",
"\n",
"Luckily, this dataset exists for free on the web. Feel free to try to find this dataset on your own, but here is the link to the dataset: https://geo.nyu.edu/catalog/nyu_2451_34572"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For your convenience, I downloaded the files and placed it on the server, so you can simply run a `wget` command and access the data. So let's go ahead and do that."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data downloaded!\n"
]
}
],
"source": [
"!wget -q -O 'newyork_data.json' https://cocl.us/new_york_dataset\n",
"print('Data downloaded!')"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"#Next, let's load the data.\n",
"with open('newyork_data.json') as json_data:\n",
" newyork_data = json.load(json_data)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"#Notice how all the relevant data is in the *features* key,\n",
"#which is basically a list of the neighborhoods.\n",
"#So, let's define a new variable that includes this data.\n",
"neighborhoods_data = newyork_data['features']"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"{'type': 'Feature',\n",
" 'id': 'nyu_2451_34572.1',\n",
" 'geometry': {'type': 'Point',\n",
" 'coordinates': [-73.84720052054902, 40.89470517661]},\n",
" 'geometry_name': 'geom',\n",
" 'properties': {'name': 'Wakefield',\n",
" 'stacked': 1,\n",
" 'annoline1': 'Wakefield',\n",
" 'annoline2': None,\n",
" 'annoline3': None,\n",
" 'annoangle': 0.0,\n",
" 'borough': 'Bronx',\n",
" 'bbox': [-73.84720052054902,\n",
" 40.89470517661,\n",
" -73.84720052054902,\n",
" 40.89470517661]}}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Let's take a look at the first item in this list.\n",
"neighborhoods_data[0]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# The next task is essentially transforming this data of nested\n",
"# Python dictionaries into a *pandas* dataframe.\n",
"# So let's start by creating an empty dataframe."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# define the dataframe columns\n",
"column_names = ['Borough', 'Neighborhood', 'Latitude', 'Longitude'] \n",
"\n",
"# instantiate the dataframe\n",
"neighborhoods_NY = pd.DataFrame(columns=column_names)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [Borough, Neighborhood, Latitude, Longitude]\n",
"Index: []"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Take a look at the empty dataframe to confirm that the columns are as intended.\n",
"neighborhoods_NY"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then let's loop through the data and fill the dataframe one row at a time."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"for data in neighborhoods_data:\n",
" borough = neighborhood_name = data['properties']['borough'] \n",
" neighborhood_name = data['properties']['name']\n",
" \n",
" neighborhood_latlon = data['geometry']['coordinates']\n",
" neighborhood_lat = neighborhood_latlon[1]\n",
" neighborhood_lon = neighborhood_latlon[0]\n",
" \n",
" neighborhoods_NY = neighborhoods_NY.append({'Borough': borough,\n",
" 'Neighborhood': neighborhood_name,\n",
" 'Latitude': neighborhood_lat,\n",
" 'Longitude': neighborhood_lon}, ignore_index=True)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Bronx</td>\n",
" <td>Wakefield</td>\n",
" <td>40.894705</td>\n",
" <td>-73.847201</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Bronx</td>\n",
" <td>Co-op City</td>\n",
" <td>40.874294</td>\n",
" <td>-73.829939</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Bronx</td>\n",
" <td>Eastchester</td>\n",
" <td>40.887556</td>\n",
" <td>-73.827806</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Bronx</td>\n",
" <td>Fieldston</td>\n",
" <td>40.895437</td>\n",
" <td>-73.905643</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bronx</td>\n",
" <td>Riverdale</td>\n",
" <td>40.890834</td>\n",
" <td>-73.912585</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude Longitude\n",
"0 Bronx Wakefield 40.894705 -73.847201\n",
"1 Bronx Co-op City 40.874294 -73.829939\n",
"2 Bronx Eastchester 40.887556 -73.827806\n",
"3 Bronx Fieldston 40.895437 -73.905643\n",
"4 Bronx Riverdale 40.890834 -73.912585"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Quickly examine the resulting dataframe.\n",
"neighborhoods_NY.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And make sure that the dataset has all 5 boroughs and 306 neighborhoods."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The dataframe has 5 boroughs and 306 neighborhoods.\n"
]
}
],
"source": [
"print('The dataframe has {} boroughs and {} neighborhoods.'.format(\n",
" len(neighborhoods_NY['Borough'].unique()),\n",
" neighborhoods_NY.shape[0]\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Bronx</td>\n",
" <td>Wakefield</td>\n",
" <td>40.894705</td>\n",
" <td>-73.847201</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Bronx</td>\n",
" <td>Co-op City</td>\n",
" <td>40.874294</td>\n",
" <td>-73.829939</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Bronx</td>\n",
" <td>Eastchester</td>\n",
" <td>40.887556</td>\n",
" <td>-73.827806</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Bronx</td>\n",
" <td>Fieldston</td>\n",
" <td>40.895437</td>\n",
" <td>-73.905643</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bronx</td>\n",
" <td>Riverdale</td>\n",
" <td>40.890834</td>\n",
" <td>-73.912585</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude Longitude city Postalcode\n",
"0 Bronx Wakefield 40.894705 -73.847201 NY NY\n",
"1 Bronx Co-op City 40.874294 -73.829939 NY NY\n",
"2 Bronx Eastchester 40.887556 -73.827806 NY NY\n",
"3 Bronx Fieldston 40.895437 -73.905643 NY NY\n",
"4 Bronx Riverdale 40.890834 -73.912585 NY NY"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# We will merge both dataframes, NY and TO, so let's include the city on them\n",
"neighborhoods_NY[\"city\"] = \"NY\"\n",
"neighborhoods_NY[\"Postalcode\"] = \"NY\"\n",
"neighborhoods_NY.head()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" \"\"\"Entry point for launching an IPython kernel.\n"
]
},
{
"data": {
"text/html": [
"<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>Postalcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>43.753259</td>\n",
" <td>-79.329656</td>\n",
" <td>TO</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M4A</td>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>43.725882</td>\n",
" <td>-79.315572</td>\n",
" <td>TO</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>43.654260</td>\n",
" <td>-79.360636</td>\n",
" <td>TO</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>43.718518</td>\n",
" <td>-79.464763</td>\n",
" <td>TO</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M7A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" <td>43.662301</td>\n",
" <td>-79.389494</td>\n",
" <td>TO</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Postalcode Borough Neighborhood \\\n",
"0 M3A North York Parkwoods \n",
"1 M4A North York Victoria Village \n",
"2 M5A Downtown Toronto Regent Park / Harbourfront \n",
"3 M6A North York Lawrence Manor / Lawrence Heights \n",
"4 M7A Downtown Toronto Queen's Park / Ontario Provincial Government \n",
"\n",
" Latitude Longitude city \n",
"0 43.753259 -79.329656 TO \n",
"1 43.725882 -79.315572 TO \n",
"2 43.654260 -79.360636 TO \n",
"3 43.718518 -79.464763 TO \n",
"4 43.662301 -79.389494 TO "
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Toronto_Neighb[\"city\"] = \"TO\"\n",
"Toronto_Neighb.head()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Bronx</td>\n",
" <td>Wakefield</td>\n",
" <td>40.894705</td>\n",
" <td>-73.847201</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Bronx</td>\n",
" <td>Co-op City</td>\n",
" <td>40.874294</td>\n",
" <td>-73.829939</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Bronx</td>\n",
" <td>Eastchester</td>\n",
" <td>40.887556</td>\n",
" <td>-73.827806</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Bronx</td>\n",
" <td>Fieldston</td>\n",
" <td>40.895437</td>\n",
" <td>-73.905643</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bronx</td>\n",
" <td>Riverdale</td>\n",
" <td>40.890834</td>\n",
" <td>-73.912585</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude Longitude city Postalcode\n",
"0 Bronx Wakefield 40.894705 -73.847201 NY NY\n",
"1 Bronx Co-op City 40.874294 -73.829939 NY NY\n",
"2 Bronx Eastchester 40.887556 -73.827806 NY NY\n",
"3 Bronx Fieldston 40.895437 -73.905643 NY NY\n",
"4 Bronx Riverdale 40.890834 -73.912585 NY NY"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Finally, we concatenate to one single Dataframe\n",
"neighb_NY_TO = pd.concat([neighborhoods_NY,Toronto_Neighb])\n",
"neighb_NY_TO.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Now here the user process starts!"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"# Creating a Picklist with NY Neighborhoods:\n",
"dropdown_Neighb = widgets.Dropdown(options = neighborhoods_NY.Neighborhood.sort_values(ascending=True),\n",
" value = \"Allerton\",description='Neighborhood:',disabled=False,)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"\n",
"caption = widgets.Label(value=' ')\n",
"\n",
"caption.value = ' '\n",
"def dropdown_Neighb_eventhandler(change):\n",
" caption.value = change.new\n"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"dropdown_Neighb.observe(dropdown_Neighb_eventhandler, names='value') "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Select your NY neighborhood on the list below, so later the system will find similar Neighborhoods in Toronto:"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5779bce468fa4e53be5adc5369bce29d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='Neighborhood:', options=('Allerton', 'Annadale', 'Arden Heights', 'Arlington', 'Arrochar…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(dropdown_Neighb)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The value selected is: \n"
]
}
],
"source": [
"print(\"The value selected is: \"+caption.value)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No value selected, defaulted to Allerton\n"
]
}
],
"source": [
"if caption.value == \" \":\n",
" print('No value selected, defaulted to Allerton');\n",
" caption.value = \"Allerton\""
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>298</th>\n",
" <td>Bronx</td>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>43.753259</td>\n",
" <td>-79.329656</td>\n",
" <td>TO</td>\n",
" <td>M3A</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>43.725882</td>\n",
" <td>-79.315572</td>\n",
" <td>TO</td>\n",
" <td>M4A</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>43.654260</td>\n",
" <td>-79.360636</td>\n",
" <td>TO</td>\n",
" <td>M5A</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>43.718518</td>\n",
" <td>-79.464763</td>\n",
" <td>TO</td>\n",
" <td>M6A</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Queen's Park / Ontario Provincial Government</td>\n",
" <td>43.662301</td>\n",
" <td>-79.389494</td>\n",
" <td>TO</td>\n",
" <td>M7A</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" <td>43.667856</td>\n",
" <td>-79.532242</td>\n",
" <td>TO</td>\n",
" <td>M9A</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Scarborough</td>\n",
" <td>Malvern / Rouge</td>\n",
" <td>43.806686</td>\n",
" <td>-79.194353</td>\n",
" <td>TO</td>\n",
" <td>M1B</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>North York</td>\n",
" <td>Don Mills</td>\n",
" <td>43.745906</td>\n",
" <td>-79.352188</td>\n",
" <td>TO</td>\n",
" <td>M3B</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>East York</td>\n",
" <td>Parkview Hill / Woodbine Gardens</td>\n",
" <td>43.706397</td>\n",
" <td>-79.309937</td>\n",
" <td>TO</td>\n",
" <td>M4B</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Garden District-Ryerson</td>\n",
" <td>43.657162</td>\n",
" <td>-79.378937</td>\n",
" <td>TO</td>\n",
" <td>M5B</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>North York</td>\n",
" <td>Glencairn</td>\n",
" <td>43.709577</td>\n",
" <td>-79.445073</td>\n",
" <td>TO</td>\n",
" <td>M6B</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>Etobicoke</td>\n",
" <td>West Deane Park / Princess Gardens / Martin Gr...</td>\n",
" <td>43.650943</td>\n",
" <td>-79.554724</td>\n",
" <td>TO</td>\n",
" <td>M9B</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>Scarborough</td>\n",
" <td>Rouge Hill / Port Union / Highland Creek</td>\n",
" <td>43.784535</td>\n",
" <td>-79.160497</td>\n",
" <td>TO</td>\n",
" <td>M1C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>North York</td>\n",
" <td>Don Mills</td>\n",
" <td>43.725900</td>\n",
" <td>-79.340923</td>\n",
" <td>TO</td>\n",
" <td>M3C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>East York</td>\n",
" <td>Woodbine Heights</td>\n",
" <td>43.695344</td>\n",
" <td>-79.318389</td>\n",
" <td>TO</td>\n",
" <td>M4C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>St. James Town</td>\n",
" <td>43.651494</td>\n",
" <td>-79.375418</td>\n",
" <td>TO</td>\n",
" <td>M5C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>York</td>\n",
" <td>Humewood-Cedarvale</td>\n",
" <td>43.693781</td>\n",
" <td>-79.428191</td>\n",
" <td>TO</td>\n",
" <td>M6C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>Etobicoke</td>\n",
" <td>Eringate / Bloordale Gardens / Old Burnhamthor...</td>\n",
" <td>43.643515</td>\n",
" <td>-79.577201</td>\n",
" <td>TO</td>\n",
" <td>M9C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>Scarborough</td>\n",
" <td>Guildwood / Morningside / West Hill</td>\n",
" <td>43.763573</td>\n",
" <td>-79.188711</td>\n",
" <td>TO</td>\n",
" <td>M1E</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>East Toronto</td>\n",
" <td>The Beaches</td>\n",
" <td>43.676357</td>\n",
" <td>-79.293031</td>\n",
" <td>TO</td>\n",
" <td>M4E</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Berczy Park</td>\n",
" <td>43.644771</td>\n",
" <td>-79.373306</td>\n",
" <td>TO</td>\n",
" <td>M5E</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>York</td>\n",
" <td>Caledonia-Fairbanks</td>\n",
" <td>43.689026</td>\n",
" <td>-79.453512</td>\n",
" <td>TO</td>\n",
" <td>M6E</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>Scarborough</td>\n",
" <td>Woburn</td>\n",
" <td>43.770992</td>\n",
" <td>-79.216917</td>\n",
" <td>TO</td>\n",
" <td>M1G</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>East York</td>\n",
" <td>Leaside</td>\n",
" <td>43.709060</td>\n",
" <td>-79.363452</td>\n",
" <td>TO</td>\n",
" <td>M4G</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Central Bay Street</td>\n",
" <td>43.657952</td>\n",
" <td>-79.387383</td>\n",
" <td>TO</td>\n",
" <td>M5G</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Christie</td>\n",
" <td>43.669542</td>\n",
" <td>-79.422564</td>\n",
" <td>TO</td>\n",
" <td>M6G</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" <td>43.773136</td>\n",
" <td>-79.239476</td>\n",
" <td>TO</td>\n",
" <td>M1H</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>North York</td>\n",
" <td>Hillcrest Village</td>\n",
" <td>43.803762</td>\n",
" <td>-79.363452</td>\n",
" <td>TO</td>\n",
" <td>M2H</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>North York</td>\n",
" <td>Bathurst Manor / Wilson Heights / Downsview North</td>\n",
" <td>43.754328</td>\n",
" <td>-79.442259</td>\n",
" <td>TO</td>\n",
" <td>M3H</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>East York</td>\n",
" <td>Thorncliffe Park</td>\n",
" <td>43.705369</td>\n",
" <td>-79.349372</td>\n",
" <td>TO</td>\n",
" <td>M4H</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Richmond / Adelaide / King</td>\n",
" <td>43.650571</td>\n",
" <td>-79.384568</td>\n",
" <td>TO</td>\n",
" <td>M5H</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>West Toronto</td>\n",
" <td>Dufferin / Dovercourt Village</td>\n",
" <td>43.669005</td>\n",
" <td>-79.442259</td>\n",
" <td>TO</td>\n",
" <td>M6H</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" <td>43.744734</td>\n",
" <td>-79.239476</td>\n",
" <td>TO</td>\n",
" <td>M1J</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>North York</td>\n",
" <td>Fairview / Henry Farm / Oriole</td>\n",
" <td>43.778517</td>\n",
" <td>-79.346556</td>\n",
" <td>TO</td>\n",
" <td>M2J</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>North York</td>\n",
" <td>Northwood Park / York University</td>\n",
" <td>43.767980</td>\n",
" <td>-79.487262</td>\n",
" <td>TO</td>\n",
" <td>M3J</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>East York</td>\n",
" <td>East Toronto</td>\n",
" <td>43.685347</td>\n",
" <td>-79.338106</td>\n",
" <td>TO</td>\n",
" <td>M4J</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Harbourfront East / Union Station / Toronto Is...</td>\n",
" <td>43.640816</td>\n",
" <td>-79.381752</td>\n",
" <td>TO</td>\n",
" <td>M5J</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>West Toronto</td>\n",
" <td>Little Portugal / Trinity</td>\n",
" <td>43.647927</td>\n",
" <td>-79.419750</td>\n",
" <td>TO</td>\n",
" <td>M6J</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>Scarborough</td>\n",
" <td>Kennedy Park / Ionview / East Birchmount Park</td>\n",
" <td>43.727929</td>\n",
" <td>-79.262029</td>\n",
" <td>TO</td>\n",
" <td>M1K</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39</th>\n",
" <td>North York</td>\n",
" <td>Bayview Village</td>\n",
" <td>43.786947</td>\n",
" <td>-79.385975</td>\n",
" <td>TO</td>\n",
" <td>M2K</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" <td>43.737473</td>\n",
" <td>-79.464763</td>\n",
" <td>TO</td>\n",
" <td>M3K</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>East Toronto</td>\n",
" <td>The Danforth West / Riverdale</td>\n",
" <td>43.679557</td>\n",
" <td>-79.352188</td>\n",
" <td>TO</td>\n",
" <td>M4K</td>\n",
" </tr>\n",
" <tr>\n",
" <th>42</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Toronto Dominion Centre / Design Exchange</td>\n",
" <td>43.647177</td>\n",
" <td>-79.381576</td>\n",
" <td>TO</td>\n",
" <td>M5K</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>West Toronto</td>\n",
" <td>Brockton / Parkdale Village / Exhibition Place</td>\n",
" <td>43.636847</td>\n",
" <td>-79.428191</td>\n",
" <td>TO</td>\n",
" <td>M6K</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile / Clairlea / Oakridge</td>\n",
" <td>43.711112</td>\n",
" <td>-79.284577</td>\n",
" <td>TO</td>\n",
" <td>M1L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>North York</td>\n",
" <td>York Mills / Silver Hills</td>\n",
" <td>43.757490</td>\n",
" <td>-79.374714</td>\n",
" <td>TO</td>\n",
" <td>M2L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" <td>43.739015</td>\n",
" <td>-79.506944</td>\n",
" <td>TO</td>\n",
" <td>M3L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47</th>\n",
" <td>East Toronto</td>\n",
" <td>India Bazaar / The Beaches West</td>\n",
" <td>43.668999</td>\n",
" <td>-79.315572</td>\n",
" <td>TO</td>\n",
" <td>M4L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>48</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Commerce Court / Victoria Hotel</td>\n",
" <td>43.648198</td>\n",
" <td>-79.379817</td>\n",
" <td>TO</td>\n",
" <td>M5L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49</th>\n",
" <td>North York</td>\n",
" <td>North Park / Maple Leaf Park / Upwood Park</td>\n",
" <td>43.713756</td>\n",
" <td>-79.490074</td>\n",
" <td>TO</td>\n",
" <td>M6L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>North York</td>\n",
" <td>Humber Summit</td>\n",
" <td>43.756303</td>\n",
" <td>-79.565963</td>\n",
" <td>TO</td>\n",
" <td>M9L</td>\n",
" </tr>\n",
" <tr>\n",
" <th>51</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside / Cliffcrest / Scarborough Village West</td>\n",
" <td>43.716316</td>\n",
" <td>-79.239476</td>\n",
" <td>TO</td>\n",
" <td>M1M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>52</th>\n",
" <td>North York</td>\n",
" <td>Willowdale / Newtonbrook</td>\n",
" <td>43.789053</td>\n",
" <td>-79.408493</td>\n",
" <td>TO</td>\n",
" <td>M2M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>53</th>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" <td>43.728496</td>\n",
" <td>-79.495697</td>\n",
" <td>TO</td>\n",
" <td>M3M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
" <td>East Toronto</td>\n",
" <td>Studio District</td>\n",
" <td>43.659526</td>\n",
" <td>-79.340923</td>\n",
" <td>TO</td>\n",
" <td>M4M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>55</th>\n",
" <td>North York</td>\n",
" <td>Bedford Park / Lawrence Manor East</td>\n",
" <td>43.733283</td>\n",
" <td>-79.419750</td>\n",
" <td>TO</td>\n",
" <td>M5M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>56</th>\n",
" <td>York</td>\n",
" <td>Del Ray / Mount Dennis / Keelsdale and Silvert...</td>\n",
" <td>43.691116</td>\n",
" <td>-79.476013</td>\n",
" <td>TO</td>\n",
" <td>M6M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>57</th>\n",
" <td>North York</td>\n",
" <td>Humberlea / Emery</td>\n",
" <td>43.724766</td>\n",
" <td>-79.532242</td>\n",
" <td>TO</td>\n",
" <td>M9M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>58</th>\n",
" <td>Scarborough</td>\n",
" <td>Birch Cliff / Cliffside West</td>\n",
" <td>43.692657</td>\n",
" <td>-79.264848</td>\n",
" <td>TO</td>\n",
" <td>M1N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>59</th>\n",
" <td>North York</td>\n",
" <td>Willowdale</td>\n",
" <td>43.770120</td>\n",
" <td>-79.408493</td>\n",
" <td>TO</td>\n",
" <td>M2N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>60</th>\n",
" <td>North York</td>\n",
" <td>Downsview</td>\n",
" <td>43.761631</td>\n",
" <td>-79.520999</td>\n",
" <td>TO</td>\n",
" <td>M3N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>61</th>\n",
" <td>Central Toronto</td>\n",
" <td>Lawrence Park</td>\n",
" <td>43.728020</td>\n",
" <td>-79.388790</td>\n",
" <td>TO</td>\n",
" <td>M4N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>62</th>\n",
" <td>Central Toronto</td>\n",
" <td>Roselawn</td>\n",
" <td>43.711695</td>\n",
" <td>-79.416936</td>\n",
" <td>TO</td>\n",
" <td>M5N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>63</th>\n",
" <td>York</td>\n",
" <td>Runnymede / The Junction North</td>\n",
" <td>43.673185</td>\n",
" <td>-79.487262</td>\n",
" <td>TO</td>\n",
" <td>M6N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>64</th>\n",
" <td>York</td>\n",
" <td>Weston</td>\n",
" <td>43.706876</td>\n",
" <td>-79.518188</td>\n",
" <td>TO</td>\n",
" <td>M9N</td>\n",
" </tr>\n",
" <tr>\n",
" <th>65</th>\n",
" <td>Scarborough</td>\n",
" <td>Dorset Park / Wexford Heights / Scarborough To...</td>\n",
" <td>43.757410</td>\n",
" <td>-79.273304</td>\n",
" <td>TO</td>\n",
" <td>M1P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>66</th>\n",
" <td>North York</td>\n",
" <td>York Mills West</td>\n",
" <td>43.752758</td>\n",
" <td>-79.400049</td>\n",
" <td>TO</td>\n",
" <td>M2P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>67</th>\n",
" <td>Central Toronto</td>\n",
" <td>Davisville North</td>\n",
" <td>43.712751</td>\n",
" <td>-79.390197</td>\n",
" <td>TO</td>\n",
" <td>M4P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>68</th>\n",
" <td>Central Toronto</td>\n",
" <td>Forest Hill North &amp; West</td>\n",
" <td>43.696948</td>\n",
" <td>-79.411307</td>\n",
" <td>TO</td>\n",
" <td>M5P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>69</th>\n",
" <td>West Toronto</td>\n",
" <td>High Park / The Junction South</td>\n",
" <td>43.661608</td>\n",
" <td>-79.464763</td>\n",
" <td>TO</td>\n",
" <td>M6P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>70</th>\n",
" <td>Etobicoke</td>\n",
" <td>Westmount</td>\n",
" <td>43.696319</td>\n",
" <td>-79.532242</td>\n",
" <td>TO</td>\n",
" <td>M9P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>71</th>\n",
" <td>Scarborough</td>\n",
" <td>Wexford / Maryvale</td>\n",
" <td>43.750072</td>\n",
" <td>-79.295849</td>\n",
" <td>TO</td>\n",
" <td>M1R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>72</th>\n",
" <td>North York</td>\n",
" <td>Willowdale</td>\n",
" <td>43.782736</td>\n",
" <td>-79.442259</td>\n",
" <td>TO</td>\n",
" <td>M2R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>73</th>\n",
" <td>Central Toronto</td>\n",
" <td>North Toronto West</td>\n",
" <td>43.715383</td>\n",
" <td>-79.405678</td>\n",
" <td>TO</td>\n",
" <td>M4R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>Central Toronto</td>\n",
" <td>The Annex / North Midtown / Yorkville</td>\n",
" <td>43.672710</td>\n",
" <td>-79.405678</td>\n",
" <td>TO</td>\n",
" <td>M5R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75</th>\n",
" <td>West Toronto</td>\n",
" <td>Parkdale / Roncesvalles</td>\n",
" <td>43.648960</td>\n",
" <td>-79.456325</td>\n",
" <td>TO</td>\n",
" <td>M6R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>76</th>\n",
" <td>Mississauga</td>\n",
" <td>Canada Post Gateway Processing Centre</td>\n",
" <td>43.636966</td>\n",
" <td>-79.615819</td>\n",
" <td>TO</td>\n",
" <td>M7R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>77</th>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsview Village / St. Phillips / Martin Grov...</td>\n",
" <td>43.688905</td>\n",
" <td>-79.554724</td>\n",
" <td>TO</td>\n",
" <td>M9R</td>\n",
" </tr>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" <td>43.794200</td>\n",
" <td>-79.262029</td>\n",
" <td>TO</td>\n",
" <td>M1S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>79</th>\n",
" <td>Central Toronto</td>\n",
" <td>Davisville</td>\n",
" <td>43.704324</td>\n",
" <td>-79.388790</td>\n",
" <td>TO</td>\n",
" <td>M4S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>University of Toronto / Harbord</td>\n",
" <td>43.662696</td>\n",
" <td>-79.400049</td>\n",
" <td>TO</td>\n",
" <td>M5S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>81</th>\n",
" <td>West Toronto</td>\n",
" <td>Runnymede / Swansea</td>\n",
" <td>43.651571</td>\n",
" <td>-79.484450</td>\n",
" <td>TO</td>\n",
" <td>M6S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>Scarborough</td>\n",
" <td>Clarks Corners / Tam O'Shanter / Sullivan</td>\n",
" <td>43.781638</td>\n",
" <td>-79.304302</td>\n",
" <td>TO</td>\n",
" <td>M1T</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>Central Toronto</td>\n",
" <td>Moore Park / Summerhill East</td>\n",
" <td>43.689574</td>\n",
" <td>-79.383160</td>\n",
" <td>TO</td>\n",
" <td>M4T</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Kensington Market / Chinatown / Grange Park</td>\n",
" <td>43.653206</td>\n",
" <td>-79.400049</td>\n",
" <td>TO</td>\n",
" <td>M5T</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>Scarborough</td>\n",
" <td>Milliken / Agincourt North / Steeles East / L'...</td>\n",
" <td>43.815252</td>\n",
" <td>-79.284577</td>\n",
" <td>TO</td>\n",
" <td>M1V</td>\n",
" </tr>\n",
" <tr>\n",
" <th>86</th>\n",
" <td>Central Toronto</td>\n",
" <td>Summerhill West / Rathnelly / South Hill / For...</td>\n",
" <td>43.686412</td>\n",
" <td>-79.400049</td>\n",
" <td>TO</td>\n",
" <td>M4V</td>\n",
" </tr>\n",
" <tr>\n",
" <th>87</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>CN Tower / King and Spadina / Railway Lands / ...</td>\n",
" <td>43.628947</td>\n",
" <td>-79.394420</td>\n",
" <td>TO</td>\n",
" <td>M5V</td>\n",
" </tr>\n",
" <tr>\n",
" <th>88</th>\n",
" <td>Etobicoke</td>\n",
" <td>New Toronto / Mimico South / Humber Bay Shores</td>\n",
" <td>43.605647</td>\n",
" <td>-79.501321</td>\n",
" <td>TO</td>\n",
" <td>M8V</td>\n",
" </tr>\n",
" <tr>\n",
" <th>89</th>\n",
" <td>Etobicoke</td>\n",
" <td>South Steeles / Silverstone / Humbergate / Jam...</td>\n",
" <td>43.739416</td>\n",
" <td>-79.588437</td>\n",
" <td>TO</td>\n",
" <td>M9V</td>\n",
" </tr>\n",
" <tr>\n",
" <th>90</th>\n",
" <td>Scarborough</td>\n",
" <td>Steeles West / L'Amoreaux West</td>\n",
" <td>43.799525</td>\n",
" <td>-79.318389</td>\n",
" <td>TO</td>\n",
" <td>M1W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>91</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Rosedale</td>\n",
" <td>43.679563</td>\n",
" <td>-79.377529</td>\n",
" <td>TO</td>\n",
" <td>M4W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Stn A PO Boxes</td>\n",
" <td>43.646435</td>\n",
" <td>-79.374846</td>\n",
" <td>TO</td>\n",
" <td>M5W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>93</th>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood / Long Branch</td>\n",
" <td>43.602414</td>\n",
" <td>-79.543484</td>\n",
" <td>TO</td>\n",
" <td>M8W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>94</th>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" <td>43.706748</td>\n",
" <td>-79.594054</td>\n",
" <td>TO</td>\n",
" <td>M9W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" <td>43.836125</td>\n",
" <td>-79.205636</td>\n",
" <td>TO</td>\n",
" <td>M1X</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>St. James Town / Cabbagetown</td>\n",
" <td>43.667967</td>\n",
" <td>-79.367675</td>\n",
" <td>TO</td>\n",
" <td>M4X</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>First Canadian Place / Underground city</td>\n",
" <td>43.648429</td>\n",
" <td>-79.382280</td>\n",
" <td>TO</td>\n",
" <td>M5X</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>Etobicoke</td>\n",
" <td>The Kingsway / Montgomery Road / Old Mill North</td>\n",
" <td>43.653654</td>\n",
" <td>-79.506944</td>\n",
" <td>TO</td>\n",
" <td>M8X</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Church and Wellesley</td>\n",
" <td>43.665860</td>\n",
" <td>-79.383160</td>\n",
" <td>TO</td>\n",
" <td>M4Y</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>East Toronto</td>\n",
" <td>Business reply mail Processing CentrE</td>\n",
" <td>43.662744</td>\n",
" <td>-79.321558</td>\n",
" <td>TO</td>\n",
" <td>M7Y</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>Etobicoke</td>\n",
" <td>Old Mill South / King's Mill Park / Sunnylea /...</td>\n",
" <td>43.636258</td>\n",
" <td>-79.498509</td>\n",
" <td>TO</td>\n",
" <td>M8Y</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico NW / The Queensway West / South of Bloo...</td>\n",
" <td>43.628841</td>\n",
" <td>-79.520999</td>\n",
" <td>TO</td>\n",
" <td>M8Z</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood \\\n",
"298 Bronx Allerton \n",
"0 North York Parkwoods \n",
"1 North York Victoria Village \n",
"2 Downtown Toronto Regent Park / Harbourfront \n",
"3 North York Lawrence Manor / Lawrence Heights \n",
"4 Downtown Toronto Queen's Park / Ontario Provincial Government \n",
"5 Etobicoke Islington Avenue \n",
"6 Scarborough Malvern / Rouge \n",
"7 North York Don Mills \n",
"8 East York Parkview Hill / Woodbine Gardens \n",
"9 Downtown Toronto Garden District-Ryerson \n",
"10 North York Glencairn \n",
"11 Etobicoke West Deane Park / Princess Gardens / Martin Gr... \n",
"12 Scarborough Rouge Hill / Port Union / Highland Creek \n",
"13 North York Don Mills \n",
"14 East York Woodbine Heights \n",
"15 Downtown Toronto St. James Town \n",
"16 York Humewood-Cedarvale \n",
"17 Etobicoke Eringate / Bloordale Gardens / Old Burnhamthor... \n",
"18 Scarborough Guildwood / Morningside / West Hill \n",
"19 East Toronto The Beaches \n",
"20 Downtown Toronto Berczy Park \n",
"21 York Caledonia-Fairbanks \n",
"22 Scarborough Woburn \n",
"23 East York Leaside \n",
"24 Downtown Toronto Central Bay Street \n",
"25 Downtown Toronto Christie \n",
"26 Scarborough Cedarbrae \n",
"27 North York Hillcrest Village \n",
"28 North York Bathurst Manor / Wilson Heights / Downsview North \n",
"29 East York Thorncliffe Park \n",
"30 Downtown Toronto Richmond / Adelaide / King \n",
"31 West Toronto Dufferin / Dovercourt Village \n",
"32 Scarborough Scarborough Village \n",
"33 North York Fairview / Henry Farm / Oriole \n",
"34 North York Northwood Park / York University \n",
"35 East York East Toronto \n",
"36 Downtown Toronto Harbourfront East / Union Station / Toronto Is... \n",
"37 West Toronto Little Portugal / Trinity \n",
"38 Scarborough Kennedy Park / Ionview / East Birchmount Park \n",
"39 North York Bayview Village \n",
"40 North York Downsview \n",
"41 East Toronto The Danforth West / Riverdale \n",
"42 Downtown Toronto Toronto Dominion Centre / Design Exchange \n",
"43 West Toronto Brockton / Parkdale Village / Exhibition Place \n",
"44 Scarborough Golden Mile / Clairlea / Oakridge \n",
"45 North York York Mills / Silver Hills \n",
"46 North York Downsview \n",
"47 East Toronto India Bazaar / The Beaches West \n",
"48 Downtown Toronto Commerce Court / Victoria Hotel \n",
"49 North York North Park / Maple Leaf Park / Upwood Park \n",
"50 North York Humber Summit \n",
"51 Scarborough Cliffside / Cliffcrest / Scarborough Village West \n",
"52 North York Willowdale / Newtonbrook \n",
"53 North York Downsview \n",
"54 East Toronto Studio District \n",
"55 North York Bedford Park / Lawrence Manor East \n",
"56 York Del Ray / Mount Dennis / Keelsdale and Silvert... \n",
"57 North York Humberlea / Emery \n",
"58 Scarborough Birch Cliff / Cliffside West \n",
"59 North York Willowdale \n",
"60 North York Downsview \n",
"61 Central Toronto Lawrence Park \n",
"62 Central Toronto Roselawn \n",
"63 York Runnymede / The Junction North \n",
"64 York Weston \n",
"65 Scarborough Dorset Park / Wexford Heights / Scarborough To... \n",
"66 North York York Mills West \n",
"67 Central Toronto Davisville North \n",
"68 Central Toronto Forest Hill North & West \n",
"69 West Toronto High Park / The Junction South \n",
"70 Etobicoke Westmount \n",
"71 Scarborough Wexford / Maryvale \n",
"72 North York Willowdale \n",
"73 Central Toronto North Toronto West \n",
"74 Central Toronto The Annex / North Midtown / Yorkville \n",
"75 West Toronto Parkdale / Roncesvalles \n",
"76 Mississauga Canada Post Gateway Processing Centre \n",
"77 Etobicoke Kingsview Village / St. Phillips / Martin Grov... \n",
"78 Scarborough Agincourt \n",
"79 Central Toronto Davisville \n",
"80 Downtown Toronto University of Toronto / Harbord \n",
"81 West Toronto Runnymede / Swansea \n",
"82 Scarborough Clarks Corners / Tam O'Shanter / Sullivan \n",
"83 Central Toronto Moore Park / Summerhill East \n",
"84 Downtown Toronto Kensington Market / Chinatown / Grange Park \n",
"85 Scarborough Milliken / Agincourt North / Steeles East / L'... \n",
"86 Central Toronto Summerhill West / Rathnelly / South Hill / For... \n",
"87 Downtown Toronto CN Tower / King and Spadina / Railway Lands / ... \n",
"88 Etobicoke New Toronto / Mimico South / Humber Bay Shores \n",
"89 Etobicoke South Steeles / Silverstone / Humbergate / Jam... \n",
"90 Scarborough Steeles West / L'Amoreaux West \n",
"91 Downtown Toronto Rosedale \n",
"92 Downtown Toronto Stn A PO Boxes \n",
"93 Etobicoke Alderwood / Long Branch \n",
"94 Etobicoke Northwest \n",
"95 Scarborough Upper Rouge \n",
"96 Downtown Toronto St. James Town / Cabbagetown \n",
"97 Downtown Toronto First Canadian Place / Underground city \n",
"98 Etobicoke The Kingsway / Montgomery Road / Old Mill North \n",
"99 Downtown Toronto Church and Wellesley \n",
"100 East Toronto Business reply mail Processing CentrE \n",
"101 Etobicoke Old Mill South / King's Mill Park / Sunnylea /... \n",
"102 Etobicoke Mimico NW / The Queensway West / South of Bloo... \n",
"\n",
" Latitude Longitude city Postalcode \n",
"298 40.865788 -73.859319 NY NY \n",
"0 43.753259 -79.329656 TO M3A \n",
"1 43.725882 -79.315572 TO M4A \n",
"2 43.654260 -79.360636 TO M5A \n",
"3 43.718518 -79.464763 TO M6A \n",
"4 43.662301 -79.389494 TO M7A \n",
"5 43.667856 -79.532242 TO M9A \n",
"6 43.806686 -79.194353 TO M1B \n",
"7 43.745906 -79.352188 TO M3B \n",
"8 43.706397 -79.309937 TO M4B \n",
"9 43.657162 -79.378937 TO M5B \n",
"10 43.709577 -79.445073 TO M6B \n",
"11 43.650943 -79.554724 TO M9B \n",
"12 43.784535 -79.160497 TO M1C \n",
"13 43.725900 -79.340923 TO M3C \n",
"14 43.695344 -79.318389 TO M4C \n",
"15 43.651494 -79.375418 TO M5C \n",
"16 43.693781 -79.428191 TO M6C \n",
"17 43.643515 -79.577201 TO M9C \n",
"18 43.763573 -79.188711 TO M1E \n",
"19 43.676357 -79.293031 TO M4E \n",
"20 43.644771 -79.373306 TO M5E \n",
"21 43.689026 -79.453512 TO M6E \n",
"22 43.770992 -79.216917 TO M1G \n",
"23 43.709060 -79.363452 TO M4G \n",
"24 43.657952 -79.387383 TO M5G \n",
"25 43.669542 -79.422564 TO M6G \n",
"26 43.773136 -79.239476 TO M1H \n",
"27 43.803762 -79.363452 TO M2H \n",
"28 43.754328 -79.442259 TO M3H \n",
"29 43.705369 -79.349372 TO M4H \n",
"30 43.650571 -79.384568 TO M5H \n",
"31 43.669005 -79.442259 TO M6H \n",
"32 43.744734 -79.239476 TO M1J \n",
"33 43.778517 -79.346556 TO M2J \n",
"34 43.767980 -79.487262 TO M3J \n",
"35 43.685347 -79.338106 TO M4J \n",
"36 43.640816 -79.381752 TO M5J \n",
"37 43.647927 -79.419750 TO M6J \n",
"38 43.727929 -79.262029 TO M1K \n",
"39 43.786947 -79.385975 TO M2K \n",
"40 43.737473 -79.464763 TO M3K \n",
"41 43.679557 -79.352188 TO M4K \n",
"42 43.647177 -79.381576 TO M5K \n",
"43 43.636847 -79.428191 TO M6K \n",
"44 43.711112 -79.284577 TO M1L \n",
"45 43.757490 -79.374714 TO M2L \n",
"46 43.739015 -79.506944 TO M3L \n",
"47 43.668999 -79.315572 TO M4L \n",
"48 43.648198 -79.379817 TO M5L \n",
"49 43.713756 -79.490074 TO M6L \n",
"50 43.756303 -79.565963 TO M9L \n",
"51 43.716316 -79.239476 TO M1M \n",
"52 43.789053 -79.408493 TO M2M \n",
"53 43.728496 -79.495697 TO M3M \n",
"54 43.659526 -79.340923 TO M4M \n",
"55 43.733283 -79.419750 TO M5M \n",
"56 43.691116 -79.476013 TO M6M \n",
"57 43.724766 -79.532242 TO M9M \n",
"58 43.692657 -79.264848 TO M1N \n",
"59 43.770120 -79.408493 TO M2N \n",
"60 43.761631 -79.520999 TO M3N \n",
"61 43.728020 -79.388790 TO M4N \n",
"62 43.711695 -79.416936 TO M5N \n",
"63 43.673185 -79.487262 TO M6N \n",
"64 43.706876 -79.518188 TO M9N \n",
"65 43.757410 -79.273304 TO M1P \n",
"66 43.752758 -79.400049 TO M2P \n",
"67 43.712751 -79.390197 TO M4P \n",
"68 43.696948 -79.411307 TO M5P \n",
"69 43.661608 -79.464763 TO M6P \n",
"70 43.696319 -79.532242 TO M9P \n",
"71 43.750072 -79.295849 TO M1R \n",
"72 43.782736 -79.442259 TO M2R \n",
"73 43.715383 -79.405678 TO M4R \n",
"74 43.672710 -79.405678 TO M5R \n",
"75 43.648960 -79.456325 TO M6R \n",
"76 43.636966 -79.615819 TO M7R \n",
"77 43.688905 -79.554724 TO M9R \n",
"78 43.794200 -79.262029 TO M1S \n",
"79 43.704324 -79.388790 TO M4S \n",
"80 43.662696 -79.400049 TO M5S \n",
"81 43.651571 -79.484450 TO M6S \n",
"82 43.781638 -79.304302 TO M1T \n",
"83 43.689574 -79.383160 TO M4T \n",
"84 43.653206 -79.400049 TO M5T \n",
"85 43.815252 -79.284577 TO M1V \n",
"86 43.686412 -79.400049 TO M4V \n",
"87 43.628947 -79.394420 TO M5V \n",
"88 43.605647 -79.501321 TO M8V \n",
"89 43.739416 -79.588437 TO M9V \n",
"90 43.799525 -79.318389 TO M1W \n",
"91 43.679563 -79.377529 TO M4W \n",
"92 43.646435 -79.374846 TO M5W \n",
"93 43.602414 -79.543484 TO M8W \n",
"94 43.706748 -79.594054 TO M9W \n",
"95 43.836125 -79.205636 TO M1X \n",
"96 43.667967 -79.367675 TO M4X \n",
"97 43.648429 -79.382280 TO M5X \n",
"98 43.653654 -79.506944 TO M8X \n",
"99 43.665860 -79.383160 TO M4Y \n",
"100 43.662744 -79.321558 TO M7Y \n",
"101 43.636258 -79.498509 TO M8Y \n",
"102 43.628841 -79.520999 TO M8Z "
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now let's concatenate the Toronto Dataframe with the record selected by the user:\n",
"# You will notice the NY record will be the first on the list.\n",
"\n",
"Toronto_Neighb = Toronto_Neighb[(Toronto_Neighb['city']=='TO')]\n",
"Toronto_Neighb = pd.concat([neighborhoods_NY[(neighborhoods_NY['Neighborhood']==caption.value)],Toronto_Neighb])\n",
"Toronto_Neighb"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>298</th>\n",
" <td>Bronx</td>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude Longitude city Postalcode\n",
"298 Bronx Allerton 40.865788 -73.859319 NY NY"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# here is the isolated record:\n",
"neighborhoods_NY[(neighborhoods_NY['Neighborhood']==caption.value)]"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"# Now let's get the venues on Foursquare!"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your credentails:\n",
"CLIENT_ID: VAHUGBJMS1OYZJ5GCHJGF121BRMAOOBZWCD135K3XEJ1ISCG\n",
"CLIENT_SECRET:CNQDHEV0R4P5YU1YPOSUAF0F2Y3QHFNLVETSRFZEEFMW0DUE\n"
]
}
],
"source": [
"#### Define Foursquare Credentials and Version\n",
"\n",
"CLIENT_ID = 'VAHUGBJMS1OYZJ5GCHJGF121BRMAOOBZWCD135K3XEJ1ISCG' # your Foursquare ID\n",
"CLIENT_SECRET = 'CNQDHEV0R4P5YU1YPOSUAF0F2Y3QHFNLVETSRFZEEFMW0DUE' # your Foursquare Secret\n",
"VERSION = '20180605' # Foursquare API version\n",
"\n",
"print('Your credentails:')\n",
"print('CLIENT_ID: ' + CLIENT_ID)\n",
"print('CLIENT_SECRET:' + CLIENT_SECRET)\n",
"\n",
"## Define other variables to Foursquare API\n",
"radius = 500\n",
"LIMIT = 100"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"## Exploring Neighborhoods in Toronto!\n",
"\n",
"def getNearbyVenues(names, latitudes, longitudes, radius=500):\n",
" \n",
" venues_list=[]\n",
" for name, lat, lng in zip(names, latitudes, longitudes):\n",
" print(name)\n",
" \n",
" # create the API request URL\n",
" url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(\n",
" CLIENT_ID, \n",
" CLIENT_SECRET, \n",
" VERSION, \n",
" lat, \n",
" lng, \n",
" radius, \n",
" LIMIT)\n",
" \n",
" # make the GET request\n",
" results = requests.get(url).json()[\"response\"]['groups'][0]['items']\n",
" \n",
" # return only relevant information for each nearby venue\n",
" venues_list.append([(\n",
" name, \n",
" lat, \n",
" lng, \n",
" v['venue']['name'], \n",
" v['venue']['location']['lat'], \n",
" v['venue']['location']['lng'], \n",
" v['venue']['categories'][0]['name']) for v in results])\n",
"\n",
" nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])\n",
" nearby_venues.columns = ['Neighborhood', \n",
" 'Neighborhood Latitude', \n",
" 'Neighborhood Longitude', \n",
" 'Venue', \n",
" 'Venue Latitude', \n",
" 'Venue Longitude', \n",
" 'Venue Category']\n",
" \n",
" return(nearby_venues)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Allerton\n",
"Parkwoods\n",
"Victoria Village\n",
"Regent Park / Harbourfront\n",
"Lawrence Manor / Lawrence Heights\n",
"Queen's Park / Ontario Provincial Government\n",
"Islington Avenue\n",
"Malvern / Rouge\n",
"Don Mills\n",
"Parkview Hill / Woodbine Gardens\n",
"Garden District-Ryerson\n",
"Glencairn\n",
"West Deane Park / Princess Gardens / Martin Grove / Islington / Cloverdale\n",
"Rouge Hill / Port Union / Highland Creek\n",
"Don Mills\n",
"Woodbine Heights\n",
"St. James Town\n",
"Humewood-Cedarvale\n",
"Eringate / Bloordale Gardens / Old Burnhamthorpe / Markland Wood\n",
"Guildwood / Morningside / West Hill\n",
"The Beaches\n",
"Berczy Park\n",
"Caledonia-Fairbanks\n",
"Woburn\n",
"Leaside\n",
"Central Bay Street\n",
"Christie\n",
"Cedarbrae\n",
"Hillcrest Village\n",
"Bathurst Manor / Wilson Heights / Downsview North\n",
"Thorncliffe Park\n",
"Richmond / Adelaide / King\n",
"Dufferin / Dovercourt Village\n",
"Scarborough Village\n",
"Fairview / Henry Farm / Oriole\n",
"Northwood Park / York University\n",
"East Toronto\n",
"Harbourfront East / Union Station / Toronto Islands\n",
"Little Portugal / Trinity\n",
"Kennedy Park / Ionview / East Birchmount Park\n",
"Bayview Village\n",
"Downsview\n",
"The Danforth West / Riverdale\n",
"Toronto Dominion Centre / Design Exchange\n",
"Brockton / Parkdale Village / Exhibition Place\n",
"Golden Mile / Clairlea / Oakridge\n",
"York Mills / Silver Hills\n",
"Downsview\n",
"India Bazaar / The Beaches West\n",
"Commerce Court / Victoria Hotel\n",
"North Park / Maple Leaf Park / Upwood Park\n",
"Humber Summit\n",
"Cliffside / Cliffcrest / Scarborough Village West\n",
"Willowdale / Newtonbrook\n",
"Downsview\n",
"Studio District\n",
"Bedford Park / Lawrence Manor East\n",
"Del Ray / Mount Dennis / Keelsdale and Silverthorn\n",
"Humberlea / Emery\n",
"Birch Cliff / Cliffside West\n",
"Willowdale\n",
"Downsview\n",
"Lawrence Park\n",
"Roselawn\n",
"Runnymede / The Junction North\n",
"Weston\n",
"Dorset Park / Wexford Heights / Scarborough Town Centre\n",
"York Mills West\n",
"Davisville North\n",
"Forest Hill North & West\n",
"High Park / The Junction South\n",
"Westmount\n",
"Wexford / Maryvale\n",
"Willowdale\n",
"North Toronto West\n",
"The Annex / North Midtown / Yorkville\n",
"Parkdale / Roncesvalles\n",
"Canada Post Gateway Processing Centre\n",
"Kingsview Village / St. Phillips / Martin Grove Gardens / Richview Gardens\n",
"Agincourt\n",
"Davisville\n",
"University of Toronto / Harbord\n",
"Runnymede / Swansea\n",
"Clarks Corners / Tam O'Shanter / Sullivan\n",
"Moore Park / Summerhill East\n",
"Kensington Market / Chinatown / Grange Park\n",
"Milliken / Agincourt North / Steeles East / L'Amoreaux East\n",
"Summerhill West / Rathnelly / South Hill / Forest Hill SE / Deer Park\n",
"CN Tower / King and Spadina / Railway Lands / Harbourfront West / Bathurst\n",
"New Toronto / Mimico South / Humber Bay Shores\n",
"South Steeles / Silverstone / Humbergate / Jamestown / Mount Olive / Beaumond Heights / Thistletown / Albion Gardens\n",
"Steeles West / L'Amoreaux West\n",
"Rosedale\n",
"Stn A PO Boxes\n",
"Alderwood / Long Branch\n",
"Northwest\n",
"Upper Rouge\n",
"St. James Town / Cabbagetown\n",
"First Canadian Place / Underground city\n",
"The Kingsway / Montgomery Road / Old Mill North\n",
"Church and Wellesley\n",
"Business reply mail Processing CentrE\n",
"Old Mill South / King's Mill Park / Sunnylea / Humber Bay / Mimico NE / The Queensway East / Royal York South East / Kingsway Park South East\n",
"Mimico NW / The Queensway West / South of Bloor / Kingsway Park South West / Royal York South West\n"
]
}
],
"source": [
"#### Running the above function on each neighborhood and\n",
"## creating a new dataframe called *toronto_venues*.\n",
"\n",
"toronto_venues = getNearbyVenues(names=Toronto_Neighb['Neighborhood'],\n",
" latitudes=Toronto_Neighb['Latitude'],\n",
" longitudes=Toronto_Neighb['Longitude'],\n",
" )\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(2159, 7)\n"
]
},
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>Neighborhood Latitude</th>\n",
" <th>Neighborhood Longitude</th>\n",
" <th>Venue</th>\n",
" <th>Venue Latitude</th>\n",
" <th>Venue Longitude</th>\n",
" <th>Venue Category</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Domenick's Pizzeria</td>\n",
" <td>40.865576</td>\n",
" <td>-73.858124</td>\n",
" <td>Pizza Place</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>White Castle</td>\n",
" <td>40.866065</td>\n",
" <td>-73.862307</td>\n",
" <td>Fast Food Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Sal &amp; Doms Bakery</td>\n",
" <td>40.865377</td>\n",
" <td>-73.855236</td>\n",
" <td>Dessert Shop</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Bronx Martial Arts Academy</td>\n",
" <td>40.865721</td>\n",
" <td>-73.857529</td>\n",
" <td>Martial Arts Dojo</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Dunkin'</td>\n",
" <td>40.865204</td>\n",
" <td>-73.859007</td>\n",
" <td>Donut Shop</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood Neighborhood Latitude Neighborhood Longitude \\\n",
"0 Allerton 40.865788 -73.859319 \n",
"1 Allerton 40.865788 -73.859319 \n",
"2 Allerton 40.865788 -73.859319 \n",
"3 Allerton 40.865788 -73.859319 \n",
"4 Allerton 40.865788 -73.859319 \n",
"\n",
" Venue Venue Latitude Venue Longitude \\\n",
"0 Domenick's Pizzeria 40.865576 -73.858124 \n",
"1 White Castle 40.866065 -73.862307 \n",
"2 Sal & Doms Bakery 40.865377 -73.855236 \n",
"3 Bronx Martial Arts Academy 40.865721 -73.857529 \n",
"4 Dunkin' 40.865204 -73.859007 \n",
"\n",
" Venue Category \n",
"0 Pizza Place \n",
"1 Fast Food Restaurant \n",
"2 Dessert Shop \n",
"3 Martial Arts Dojo \n",
"4 Donut Shop "
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#### Let's check the size of the resulting dataframe\n",
"\n",
"print(toronto_venues.shape)\n",
"toronto_venues.head()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood Latitude</th>\n",
" <th>Neighborhood Longitude</th>\n",
" <th>Venue</th>\n",
" <th>Venue Latitude</th>\n",
" <th>Venue Longitude</th>\n",
" <th>Venue Category</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Neighborhood</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Agincourt</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Alderwood / Long Branch</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Allerton</th>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Bathurst Manor / Wilson Heights / Downsview North</th>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Bayview Village</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Bedford Park / Lawrence Manor East</th>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Berczy Park</th>\n",
" <td>56</td>\n",
" <td>56</td>\n",
" <td>56</td>\n",
" <td>56</td>\n",
" <td>56</td>\n",
" <td>56</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Birch Cliff / Cliffside West</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Brockton / Parkdale Village / Exhibition Place</th>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Business reply mail Processing CentrE</th>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>CN Tower / King and Spadina / Railway Lands / Harbourfront West / Bathurst</th>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Caledonia-Fairbanks</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Canada Post Gateway Processing Centre</th>\n",
" <td>13</td>\n",
" <td>13</td>\n",
" <td>13</td>\n",
" <td>13</td>\n",
" <td>13</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Cedarbrae</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Central Bay Street</th>\n",
" <td>64</td>\n",
" <td>64</td>\n",
" <td>64</td>\n",
" <td>64</td>\n",
" <td>64</td>\n",
" <td>64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Christie</th>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Church and Wellesley</th>\n",
" <td>75</td>\n",
" <td>75</td>\n",
" <td>75</td>\n",
" <td>75</td>\n",
" <td>75</td>\n",
" <td>75</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Clarks Corners / Tam O'Shanter / Sullivan</th>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Cliffside / Cliffcrest / Scarborough Village West</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Commerce Court / Victoria Hotel</th>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Davisville</th>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Davisville North</th>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Del Ray / Mount Dennis / Keelsdale and Silverthorn</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Don Mills</th>\n",
" <td>26</td>\n",
" <td>26</td>\n",
" <td>26</td>\n",
" <td>26</td>\n",
" <td>26</td>\n",
" <td>26</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Dorset Park / Wexford Heights / Scarborough Town Centre</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Downsview</th>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Dufferin / Dovercourt Village</th>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>East Toronto</th>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Eringate / Bloordale Gardens / Old Burnhamthorpe / Markland Wood</th>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fairview / Henry Farm / Oriole</th>\n",
" <td>66</td>\n",
" <td>66</td>\n",
" <td>66</td>\n",
" <td>66</td>\n",
" <td>66</td>\n",
" <td>66</td>\n",
" </tr>\n",
" <tr>\n",
" <th>First Canadian Place / Underground city</th>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Forest Hill North &amp; West</th>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Garden District-Ryerson</th>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Glencairn</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Golden Mile / Clairlea / Oakridge</th>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Guildwood / Morningside / West Hill</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Harbourfront East / Union Station / Toronto Islands</th>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>High Park / The Junction South</th>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" <td>25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Hillcrest Village</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Humber Summit</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Humberlea / Emery</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Humewood-Cedarvale</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>India Bazaar / The Beaches West</th>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" <td>24</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Kennedy Park / Ionview / East Birchmount Park</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Kensington Market / Chinatown / Grange Park</th>\n",
" <td>62</td>\n",
" <td>62</td>\n",
" <td>62</td>\n",
" <td>62</td>\n",
" <td>62</td>\n",
" <td>62</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Kingsview Village / St. Phillips / Martin Grove Gardens / Richview Gardens</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Lawrence Manor / Lawrence Heights</th>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Lawrence Park</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Leaside</th>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Little Portugal / Trinity</th>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Malvern / Rouge</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Milliken / Agincourt North / Steeles East / L'Amoreaux East</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Mimico NW / The Queensway West / South of Bloor / Kingsway Park South West / Royal York South West</th>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Moore Park / Summerhill East</th>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>New Toronto / Mimico South / Humber Bay Shores</th>\n",
" <td>12</td>\n",
" <td>12</td>\n",
" <td>12</td>\n",
" <td>12</td>\n",
" <td>12</td>\n",
" <td>12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>North Park / Maple Leaf Park / Upwood Park</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>North Toronto West</th>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" <td>20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Northwest</th>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Northwood Park / York University</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Old Mill South / King's Mill Park / Sunnylea / Humber Bay / Mimico NE / The Queensway East / Royal York South East / Kingsway Park South East</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Parkdale / Roncesvalles</th>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Parkview Hill / Woodbine Gardens</th>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Parkwoods</th>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Queen's Park / Ontario Provincial Government</th>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Regent Park / Harbourfront</th>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" <td>44</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Richmond / Adelaide / King</th>\n",
" <td>92</td>\n",
" <td>92</td>\n",
" <td>92</td>\n",
" <td>92</td>\n",
" <td>92</td>\n",
" <td>92</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rosedale</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Roselawn</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Rouge Hill / Port Union / Highland Creek</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Runnymede / Swansea</th>\n",
" <td>38</td>\n",
" <td>38</td>\n",
" <td>38</td>\n",
" <td>38</td>\n",
" <td>38</td>\n",
" <td>38</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Runnymede / The Junction North</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Scarborough Village</th>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>South Steeles / Silverstone / Humbergate / Jamestown / Mount Olive / Beaumond Heights / Thistletown / Albion Gardens</th>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>St. James Town</th>\n",
" <td>78</td>\n",
" <td>78</td>\n",
" <td>78</td>\n",
" <td>78</td>\n",
" <td>78</td>\n",
" <td>78</td>\n",
" </tr>\n",
" <tr>\n",
" <th>St. James Town / Cabbagetown</th>\n",
" <td>46</td>\n",
" <td>46</td>\n",
" <td>46</td>\n",
" <td>46</td>\n",
" <td>46</td>\n",
" <td>46</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Steeles West / L'Amoreaux West</th>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Stn A PO Boxes</th>\n",
" <td>96</td>\n",
" <td>96</td>\n",
" <td>96</td>\n",
" <td>96</td>\n",
" <td>96</td>\n",
" <td>96</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Studio District</th>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Summerhill West / Rathnelly / South Hill / Forest Hill SE / Deer Park</th>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>The Annex / North Midtown / Yorkville</th>\n",
" <td>21</td>\n",
" <td>21</td>\n",
" <td>21</td>\n",
" <td>21</td>\n",
" <td>21</td>\n",
" <td>21</td>\n",
" </tr>\n",
" <tr>\n",
" <th>The Beaches</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>The Danforth West / Riverdale</th>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" <td>43</td>\n",
" </tr>\n",
" <tr>\n",
" <th>The Kingsway / Montgomery Road / Old Mill North</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Thorncliffe Park</th>\n",
" <td>22</td>\n",
" <td>22</td>\n",
" <td>22</td>\n",
" <td>22</td>\n",
" <td>22</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Toronto Dominion Centre / Design Exchange</th>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>University of Toronto / Harbord</th>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" <td>34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Victoria Village</th>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Westmount</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Weston</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Wexford / Maryvale</th>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Willowdale</th>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" <td>40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Woburn</th>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Woodbine Heights</th>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>York Mills / Silver Hills</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>York Mills West</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood Latitude \\\n",
"Neighborhood \n",
"Agincourt 5 \n",
"Alderwood / Long Branch 8 \n",
"Allerton 29 \n",
"Bathurst Manor / Wilson Heights / Downsview North 20 \n",
"Bayview Village 4 \n",
"Bedford Park / Lawrence Manor East 23 \n",
"Berczy Park 56 \n",
"Birch Cliff / Cliffside West 5 \n",
"Brockton / Parkdale Village / Exhibition Place 24 \n",
"Business reply mail Processing CentrE 16 \n",
"CN Tower / King and Spadina / Railway Lands / H... 16 \n",
"Caledonia-Fairbanks 4 \n",
"Canada Post Gateway Processing Centre 13 \n",
"Cedarbrae 8 \n",
"Central Bay Street 64 \n",
"Christie 17 \n",
"Church and Wellesley 75 \n",
"Clarks Corners / Tam O'Shanter / Sullivan 15 \n",
"Cliffside / Cliffcrest / Scarborough Village West 2 \n",
"Commerce Court / Victoria Hotel 100 \n",
"Davisville 33 \n",
"Davisville North 9 \n",
"Del Ray / Mount Dennis / Keelsdale and Silverthorn 4 \n",
"Don Mills 26 \n",
"Dorset Park / Wexford Heights / Scarborough Tow... 7 \n",
"Downsview 17 \n",
"Dufferin / Dovercourt Village 16 \n",
"East Toronto 3 \n",
"Eringate / Bloordale Gardens / Old Burnhamthorp... 9 \n",
"Fairview / Henry Farm / Oriole 66 \n",
"First Canadian Place / Underground city 100 \n",
"Forest Hill North & West 6 \n",
"Garden District-Ryerson 100 \n",
"Glencairn 5 \n",
"Golden Mile / Clairlea / Oakridge 9 \n",
"Guildwood / Morningside / West Hill 7 \n",
"Harbourfront East / Union Station / Toronto Isl... 100 \n",
"High Park / The Junction South 25 \n",
"Hillcrest Village 4 \n",
"Humber Summit 2 \n",
"Humberlea / Emery 1 \n",
"Humewood-Cedarvale 4 \n",
"India Bazaar / The Beaches West 24 \n",
"Kennedy Park / Ionview / East Birchmount Park 5 \n",
"Kensington Market / Chinatown / Grange Park 62 \n",
"Kingsview Village / St. Phillips / Martin Grove... 4 \n",
"Lawrence Manor / Lawrence Heights 15 \n",
"Lawrence Park 4 \n",
"Leaside 33 \n",
"Little Portugal / Trinity 43 \n",
"Malvern / Rouge 1 \n",
"Milliken / Agincourt North / Steeles East / L'A... 2 \n",
"Mimico NW / The Queensway West / South of Bloor... 14 \n",
"Moore Park / Summerhill East 3 \n",
"New Toronto / Mimico South / Humber Bay Shores 12 \n",
"North Park / Maple Leaf Park / Upwood Park 4 \n",
"North Toronto West 20 \n",
"Northwest 3 \n",
"Northwood Park / York University 5 \n",
"Old Mill South / King's Mill Park / Sunnylea / ... 1 \n",
"Parkdale / Roncesvalles 15 \n",
"Parkview Hill / Woodbine Gardens 10 \n",
"Parkwoods 3 \n",
"Queen's Park / Ontario Provincial Government 34 \n",
"Regent Park / Harbourfront 44 \n",
"Richmond / Adelaide / King 92 \n",
"Rosedale 4 \n",
"Roselawn 1 \n",
"Rouge Hill / Port Union / Highland Creek 1 \n",
"Runnymede / Swansea 38 \n",
"Runnymede / The Junction North 4 \n",
"Scarborough Village 3 \n",
"South Steeles / Silverstone / Humbergate / Jame... 9 \n",
"St. James Town 78 \n",
"St. James Town / Cabbagetown 46 \n",
"Steeles West / L'Amoreaux West 14 \n",
"Stn A PO Boxes 96 \n",
"Studio District 40 \n",
"Summerhill West / Rathnelly / South Hill / Fore... 16 \n",
"The Annex / North Midtown / Yorkville 21 \n",
"The Beaches 5 \n",
"The Danforth West / Riverdale 43 \n",
"The Kingsway / Montgomery Road / Old Mill North 2 \n",
"Thorncliffe Park 22 \n",
"Toronto Dominion Centre / Design Exchange 100 \n",
"University of Toronto / Harbord 34 \n",
"Victoria Village 5 \n",
"Westmount 7 \n",
"Weston 2 \n",
"Wexford / Maryvale 6 \n",
"Willowdale 40 \n",
"Woburn 3 \n",
"Woodbine Heights 6 \n",
"York Mills / Silver Hills 1 \n",
"York Mills West 2 \n",
"\n",
" Neighborhood Longitude \\\n",
"Neighborhood \n",
"Agincourt 5 \n",
"Alderwood / Long Branch 8 \n",
"Allerton 29 \n",
"Bathurst Manor / Wilson Heights / Downsview North 20 \n",
"Bayview Village 4 \n",
"Bedford Park / Lawrence Manor East 23 \n",
"Berczy Park 56 \n",
"Birch Cliff / Cliffside West 5 \n",
"Brockton / Parkdale Village / Exhibition Place 24 \n",
"Business reply mail Processing CentrE 16 \n",
"CN Tower / King and Spadina / Railway Lands / H... 16 \n",
"Caledonia-Fairbanks 4 \n",
"Canada Post Gateway Processing Centre 13 \n",
"Cedarbrae 8 \n",
"Central Bay Street 64 \n",
"Christie 17 \n",
"Church and Wellesley 75 \n",
"Clarks Corners / Tam O'Shanter / Sullivan 15 \n",
"Cliffside / Cliffcrest / Scarborough Village West 2 \n",
"Commerce Court / Victoria Hotel 100 \n",
"Davisville 33 \n",
"Davisville North 9 \n",
"Del Ray / Mount Dennis / Keelsdale and Silverthorn 4 \n",
"Don Mills 26 \n",
"Dorset Park / Wexford Heights / Scarborough Tow... 7 \n",
"Downsview 17 \n",
"Dufferin / Dovercourt Village 16 \n",
"East Toronto 3 \n",
"Eringate / Bloordale Gardens / Old Burnhamthorp... 9 \n",
"Fairview / Henry Farm / Oriole 66 \n",
"First Canadian Place / Underground city 100 \n",
"Forest Hill North & West 6 \n",
"Garden District-Ryerson 100 \n",
"Glencairn 5 \n",
"Golden Mile / Clairlea / Oakridge 9 \n",
"Guildwood / Morningside / West Hill 7 \n",
"Harbourfront East / Union Station / Toronto Isl... 100 \n",
"High Park / The Junction South 25 \n",
"Hillcrest Village 4 \n",
"Humber Summit 2 \n",
"Humberlea / Emery 1 \n",
"Humewood-Cedarvale 4 \n",
"India Bazaar / The Beaches West 24 \n",
"Kennedy Park / Ionview / East Birchmount Park 5 \n",
"Kensington Market / Chinatown / Grange Park 62 \n",
"Kingsview Village / St. Phillips / Martin Grove... 4 \n",
"Lawrence Manor / Lawrence Heights 15 \n",
"Lawrence Park 4 \n",
"Leaside 33 \n",
"Little Portugal / Trinity 43 \n",
"Malvern / Rouge 1 \n",
"Milliken / Agincourt North / Steeles East / L'A... 2 \n",
"Mimico NW / The Queensway West / South of Bloor... 14 \n",
"Moore Park / Summerhill East 3 \n",
"New Toronto / Mimico South / Humber Bay Shores 12 \n",
"North Park / Maple Leaf Park / Upwood Park 4 \n",
"North Toronto West 20 \n",
"Northwest 3 \n",
"Northwood Park / York University 5 \n",
"Old Mill South / King's Mill Park / Sunnylea / ... 1 \n",
"Parkdale / Roncesvalles 15 \n",
"Parkview Hill / Woodbine Gardens 10 \n",
"Parkwoods 3 \n",
"Queen's Park / Ontario Provincial Government 34 \n",
"Regent Park / Harbourfront 44 \n",
"Richmond / Adelaide / King 92 \n",
"Rosedale 4 \n",
"Roselawn 1 \n",
"Rouge Hill / Port Union / Highland Creek 1 \n",
"Runnymede / Swansea 38 \n",
"Runnymede / The Junction North 4 \n",
"Scarborough Village 3 \n",
"South Steeles / Silverstone / Humbergate / Jame... 9 \n",
"St. James Town 78 \n",
"St. James Town / Cabbagetown 46 \n",
"Steeles West / L'Amoreaux West 14 \n",
"Stn A PO Boxes 96 \n",
"Studio District 40 \n",
"Summerhill West / Rathnelly / South Hill / Fore... 16 \n",
"The Annex / North Midtown / Yorkville 21 \n",
"The Beaches 5 \n",
"The Danforth West / Riverdale 43 \n",
"The Kingsway / Montgomery Road / Old Mill North 2 \n",
"Thorncliffe Park 22 \n",
"Toronto Dominion Centre / Design Exchange 100 \n",
"University of Toronto / Harbord 34 \n",
"Victoria Village 5 \n",
"Westmount 7 \n",
"Weston 2 \n",
"Wexford / Maryvale 6 \n",
"Willowdale 40 \n",
"Woburn 3 \n",
"Woodbine Heights 6 \n",
"York Mills / Silver Hills 1 \n",
"York Mills West 2 \n",
"\n",
" Venue Venue Latitude \\\n",
"Neighborhood \n",
"Agincourt 5 5 \n",
"Alderwood / Long Branch 8 8 \n",
"Allerton 29 29 \n",
"Bathurst Manor / Wilson Heights / Downsview North 20 20 \n",
"Bayview Village 4 4 \n",
"Bedford Park / Lawrence Manor East 23 23 \n",
"Berczy Park 56 56 \n",
"Birch Cliff / Cliffside West 5 5 \n",
"Brockton / Parkdale Village / Exhibition Place 24 24 \n",
"Business reply mail Processing CentrE 16 16 \n",
"CN Tower / King and Spadina / Railway Lands / H... 16 16 \n",
"Caledonia-Fairbanks 4 4 \n",
"Canada Post Gateway Processing Centre 13 13 \n",
"Cedarbrae 8 8 \n",
"Central Bay Street 64 64 \n",
"Christie 17 17 \n",
"Church and Wellesley 75 75 \n",
"Clarks Corners / Tam O'Shanter / Sullivan 15 15 \n",
"Cliffside / Cliffcrest / Scarborough Village West 2 2 \n",
"Commerce Court / Victoria Hotel 100 100 \n",
"Davisville 33 33 \n",
"Davisville North 9 9 \n",
"Del Ray / Mount Dennis / Keelsdale and Silverthorn 4 4 \n",
"Don Mills 26 26 \n",
"Dorset Park / Wexford Heights / Scarborough Tow... 7 7 \n",
"Downsview 17 17 \n",
"Dufferin / Dovercourt Village 16 16 \n",
"East Toronto 3 3 \n",
"Eringate / Bloordale Gardens / Old Burnhamthorp... 9 9 \n",
"Fairview / Henry Farm / Oriole 66 66 \n",
"First Canadian Place / Underground city 100 100 \n",
"Forest Hill North & West 6 6 \n",
"Garden District-Ryerson 100 100 \n",
"Glencairn 5 5 \n",
"Golden Mile / Clairlea / Oakridge 9 9 \n",
"Guildwood / Morningside / West Hill 7 7 \n",
"Harbourfront East / Union Station / Toronto Isl... 100 100 \n",
"High Park / The Junction South 25 25 \n",
"Hillcrest Village 4 4 \n",
"Humber Summit 2 2 \n",
"Humberlea / Emery 1 1 \n",
"Humewood-Cedarvale 4 4 \n",
"India Bazaar / The Beaches West 24 24 \n",
"Kennedy Park / Ionview / East Birchmount Park 5 5 \n",
"Kensington Market / Chinatown / Grange Park 62 62 \n",
"Kingsview Village / St. Phillips / Martin Grove... 4 4 \n",
"Lawrence Manor / Lawrence Heights 15 15 \n",
"Lawrence Park 4 4 \n",
"Leaside 33 33 \n",
"Little Portugal / Trinity 43 43 \n",
"Malvern / Rouge 1 1 \n",
"Milliken / Agincourt North / Steeles East / L'A... 2 2 \n",
"Mimico NW / The Queensway West / South of Bloor... 14 14 \n",
"Moore Park / Summerhill East 3 3 \n",
"New Toronto / Mimico South / Humber Bay Shores 12 12 \n",
"North Park / Maple Leaf Park / Upwood Park 4 4 \n",
"North Toronto West 20 20 \n",
"Northwest 3 3 \n",
"Northwood Park / York University 5 5 \n",
"Old Mill South / King's Mill Park / Sunnylea / ... 1 1 \n",
"Parkdale / Roncesvalles 15 15 \n",
"Parkview Hill / Woodbine Gardens 10 10 \n",
"Parkwoods 3 3 \n",
"Queen's Park / Ontario Provincial Government 34 34 \n",
"Regent Park / Harbourfront 44 44 \n",
"Richmond / Adelaide / King 92 92 \n",
"Rosedale 4 4 \n",
"Roselawn 1 1 \n",
"Rouge Hill / Port Union / Highland Creek 1 1 \n",
"Runnymede / Swansea 38 38 \n",
"Runnymede / The Junction North 4 4 \n",
"Scarborough Village 3 3 \n",
"South Steeles / Silverstone / Humbergate / Jame... 9 9 \n",
"St. James Town 78 78 \n",
"St. James Town / Cabbagetown 46 46 \n",
"Steeles West / L'Amoreaux West 14 14 \n",
"Stn A PO Boxes 96 96 \n",
"Studio District 40 40 \n",
"Summerhill West / Rathnelly / South Hill / Fore... 16 16 \n",
"The Annex / North Midtown / Yorkville 21 21 \n",
"The Beaches 5 5 \n",
"The Danforth West / Riverdale 43 43 \n",
"The Kingsway / Montgomery Road / Old Mill North 2 2 \n",
"Thorncliffe Park 22 22 \n",
"Toronto Dominion Centre / Design Exchange 100 100 \n",
"University of Toronto / Harbord 34 34 \n",
"Victoria Village 5 5 \n",
"Westmount 7 7 \n",
"Weston 2 2 \n",
"Wexford / Maryvale 6 6 \n",
"Willowdale 40 40 \n",
"Woburn 3 3 \n",
"Woodbine Heights 6 6 \n",
"York Mills / Silver Hills 1 1 \n",
"York Mills West 2 2 \n",
"\n",
" Venue Longitude \\\n",
"Neighborhood \n",
"Agincourt 5 \n",
"Alderwood / Long Branch 8 \n",
"Allerton 29 \n",
"Bathurst Manor / Wilson Heights / Downsview North 20 \n",
"Bayview Village 4 \n",
"Bedford Park / Lawrence Manor East 23 \n",
"Berczy Park 56 \n",
"Birch Cliff / Cliffside West 5 \n",
"Brockton / Parkdale Village / Exhibition Place 24 \n",
"Business reply mail Processing CentrE 16 \n",
"CN Tower / King and Spadina / Railway Lands / H... 16 \n",
"Caledonia-Fairbanks 4 \n",
"Canada Post Gateway Processing Centre 13 \n",
"Cedarbrae 8 \n",
"Central Bay Street 64 \n",
"Christie 17 \n",
"Church and Wellesley 75 \n",
"Clarks Corners / Tam O'Shanter / Sullivan 15 \n",
"Cliffside / Cliffcrest / Scarborough Village West 2 \n",
"Commerce Court / Victoria Hotel 100 \n",
"Davisville 33 \n",
"Davisville North 9 \n",
"Del Ray / Mount Dennis / Keelsdale and Silverthorn 4 \n",
"Don Mills 26 \n",
"Dorset Park / Wexford Heights / Scarborough Tow... 7 \n",
"Downsview 17 \n",
"Dufferin / Dovercourt Village 16 \n",
"East Toronto 3 \n",
"Eringate / Bloordale Gardens / Old Burnhamthorp... 9 \n",
"Fairview / Henry Farm / Oriole 66 \n",
"First Canadian Place / Underground city 100 \n",
"Forest Hill North & West 6 \n",
"Garden District-Ryerson 100 \n",
"Glencairn 5 \n",
"Golden Mile / Clairlea / Oakridge 9 \n",
"Guildwood / Morningside / West Hill 7 \n",
"Harbourfront East / Union Station / Toronto Isl... 100 \n",
"High Park / The Junction South 25 \n",
"Hillcrest Village 4 \n",
"Humber Summit 2 \n",
"Humberlea / Emery 1 \n",
"Humewood-Cedarvale 4 \n",
"India Bazaar / The Beaches West 24 \n",
"Kennedy Park / Ionview / East Birchmount Park 5 \n",
"Kensington Market / Chinatown / Grange Park 62 \n",
"Kingsview Village / St. Phillips / Martin Grove... 4 \n",
"Lawrence Manor / Lawrence Heights 15 \n",
"Lawrence Park 4 \n",
"Leaside 33 \n",
"Little Portugal / Trinity 43 \n",
"Malvern / Rouge 1 \n",
"Milliken / Agincourt North / Steeles East / L'A... 2 \n",
"Mimico NW / The Queensway West / South of Bloor... 14 \n",
"Moore Park / Summerhill East 3 \n",
"New Toronto / Mimico South / Humber Bay Shores 12 \n",
"North Park / Maple Leaf Park / Upwood Park 4 \n",
"North Toronto West 20 \n",
"Northwest 3 \n",
"Northwood Park / York University 5 \n",
"Old Mill South / King's Mill Park / Sunnylea / ... 1 \n",
"Parkdale / Roncesvalles 15 \n",
"Parkview Hill / Woodbine Gardens 10 \n",
"Parkwoods 3 \n",
"Queen's Park / Ontario Provincial Government 34 \n",
"Regent Park / Harbourfront 44 \n",
"Richmond / Adelaide / King 92 \n",
"Rosedale 4 \n",
"Roselawn 1 \n",
"Rouge Hill / Port Union / Highland Creek 1 \n",
"Runnymede / Swansea 38 \n",
"Runnymede / The Junction North 4 \n",
"Scarborough Village 3 \n",
"South Steeles / Silverstone / Humbergate / Jame... 9 \n",
"St. James Town 78 \n",
"St. James Town / Cabbagetown 46 \n",
"Steeles West / L'Amoreaux West 14 \n",
"Stn A PO Boxes 96 \n",
"Studio District 40 \n",
"Summerhill West / Rathnelly / South Hill / Fore... 16 \n",
"The Annex / North Midtown / Yorkville 21 \n",
"The Beaches 5 \n",
"The Danforth West / Riverdale 43 \n",
"The Kingsway / Montgomery Road / Old Mill North 2 \n",
"Thorncliffe Park 22 \n",
"Toronto Dominion Centre / Design Exchange 100 \n",
"University of Toronto / Harbord 34 \n",
"Victoria Village 5 \n",
"Westmount 7 \n",
"Weston 2 \n",
"Wexford / Maryvale 6 \n",
"Willowdale 40 \n",
"Woburn 3 \n",
"Woodbine Heights 6 \n",
"York Mills / Silver Hills 1 \n",
"York Mills West 2 \n",
"\n",
" Venue Category \n",
"Neighborhood \n",
"Agincourt 5 \n",
"Alderwood / Long Branch 8 \n",
"Allerton 29 \n",
"Bathurst Manor / Wilson Heights / Downsview North 20 \n",
"Bayview Village 4 \n",
"Bedford Park / Lawrence Manor East 23 \n",
"Berczy Park 56 \n",
"Birch Cliff / Cliffside West 5 \n",
"Brockton / Parkdale Village / Exhibition Place 24 \n",
"Business reply mail Processing CentrE 16 \n",
"CN Tower / King and Spadina / Railway Lands / H... 16 \n",
"Caledonia-Fairbanks 4 \n",
"Canada Post Gateway Processing Centre 13 \n",
"Cedarbrae 8 \n",
"Central Bay Street 64 \n",
"Christie 17 \n",
"Church and Wellesley 75 \n",
"Clarks Corners / Tam O'Shanter / Sullivan 15 \n",
"Cliffside / Cliffcrest / Scarborough Village West 2 \n",
"Commerce Court / Victoria Hotel 100 \n",
"Davisville 33 \n",
"Davisville North 9 \n",
"Del Ray / Mount Dennis / Keelsdale and Silverthorn 4 \n",
"Don Mills 26 \n",
"Dorset Park / Wexford Heights / Scarborough Tow... 7 \n",
"Downsview 17 \n",
"Dufferin / Dovercourt Village 16 \n",
"East Toronto 3 \n",
"Eringate / Bloordale Gardens / Old Burnhamthorp... 9 \n",
"Fairview / Henry Farm / Oriole 66 \n",
"First Canadian Place / Underground city 100 \n",
"Forest Hill North & West 6 \n",
"Garden District-Ryerson 100 \n",
"Glencairn 5 \n",
"Golden Mile / Clairlea / Oakridge 9 \n",
"Guildwood / Morningside / West Hill 7 \n",
"Harbourfront East / Union Station / Toronto Isl... 100 \n",
"High Park / The Junction South 25 \n",
"Hillcrest Village 4 \n",
"Humber Summit 2 \n",
"Humberlea / Emery 1 \n",
"Humewood-Cedarvale 4 \n",
"India Bazaar / The Beaches West 24 \n",
"Kennedy Park / Ionview / East Birchmount Park 5 \n",
"Kensington Market / Chinatown / Grange Park 62 \n",
"Kingsview Village / St. Phillips / Martin Grove... 4 \n",
"Lawrence Manor / Lawrence Heights 15 \n",
"Lawrence Park 4 \n",
"Leaside 33 \n",
"Little Portugal / Trinity 43 \n",
"Malvern / Rouge 1 \n",
"Milliken / Agincourt North / Steeles East / L'A... 2 \n",
"Mimico NW / The Queensway West / South of Bloor... 14 \n",
"Moore Park / Summerhill East 3 \n",
"New Toronto / Mimico South / Humber Bay Shores 12 \n",
"North Park / Maple Leaf Park / Upwood Park 4 \n",
"North Toronto West 20 \n",
"Northwest 3 \n",
"Northwood Park / York University 5 \n",
"Old Mill South / King's Mill Park / Sunnylea / ... 1 \n",
"Parkdale / Roncesvalles 15 \n",
"Parkview Hill / Woodbine Gardens 10 \n",
"Parkwoods 3 \n",
"Queen's Park / Ontario Provincial Government 34 \n",
"Regent Park / Harbourfront 44 \n",
"Richmond / Adelaide / King 92 \n",
"Rosedale 4 \n",
"Roselawn 1 \n",
"Rouge Hill / Port Union / Highland Creek 1 \n",
"Runnymede / Swansea 38 \n",
"Runnymede / The Junction North 4 \n",
"Scarborough Village 3 \n",
"South Steeles / Silverstone / Humbergate / Jame... 9 \n",
"St. James Town 78 \n",
"St. James Town / Cabbagetown 46 \n",
"Steeles West / L'Amoreaux West 14 \n",
"Stn A PO Boxes 96 \n",
"Studio District 40 \n",
"Summerhill West / Rathnelly / South Hill / Fore... 16 \n",
"The Annex / North Midtown / Yorkville 21 \n",
"The Beaches 5 \n",
"The Danforth West / Riverdale 43 \n",
"The Kingsway / Montgomery Road / Old Mill North 2 \n",
"Thorncliffe Park 22 \n",
"Toronto Dominion Centre / Design Exchange 100 \n",
"University of Toronto / Harbord 34 \n",
"Victoria Village 5 \n",
"Westmount 7 \n",
"Weston 2 \n",
"Wexford / Maryvale 6 \n",
"Willowdale 40 \n",
"Woburn 3 \n",
"Woodbine Heights 6 \n",
"York Mills / Silver Hills 1 \n",
"York Mills West 2 "
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Let's check how many venues were returned for each neighborhood\n",
"toronto_venues.groupby('Neighborhood').count()"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 274 uniques categories.\n"
]
}
],
"source": [
"## Let's find out how many unique categories can be curated from all the returned venues\n",
"print('There are {} uniques categories.'.format(len(toronto_venues['Venue Category'].unique())))"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>Neighborhood Latitude</th>\n",
" <th>Neighborhood Longitude</th>\n",
" <th>Venue</th>\n",
" <th>Venue Latitude</th>\n",
" <th>Venue Longitude</th>\n",
" <th>Venue Category</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Domenick's Pizzeria</td>\n",
" <td>40.865576</td>\n",
" <td>-73.858124</td>\n",
" <td>Pizza Place</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>White Castle</td>\n",
" <td>40.866065</td>\n",
" <td>-73.862307</td>\n",
" <td>Fast Food Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Sal &amp; Doms Bakery</td>\n",
" <td>40.865377</td>\n",
" <td>-73.855236</td>\n",
" <td>Dessert Shop</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Bronx Martial Arts Academy</td>\n",
" <td>40.865721</td>\n",
" <td>-73.857529</td>\n",
" <td>Martial Arts Dojo</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Dunkin'</td>\n",
" <td>40.865204</td>\n",
" <td>-73.859007</td>\n",
" <td>Donut Shop</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood Neighborhood Latitude Neighborhood Longitude \\\n",
"0 Allerton 40.865788 -73.859319 \n",
"1 Allerton 40.865788 -73.859319 \n",
"2 Allerton 40.865788 -73.859319 \n",
"3 Allerton 40.865788 -73.859319 \n",
"4 Allerton 40.865788 -73.859319 \n",
"\n",
" Venue Venue Latitude Venue Longitude \\\n",
"0 Domenick's Pizzeria 40.865576 -73.858124 \n",
"1 White Castle 40.866065 -73.862307 \n",
"2 Sal & Doms Bakery 40.865377 -73.855236 \n",
"3 Bronx Martial Arts Academy 40.865721 -73.857529 \n",
"4 Dunkin' 40.865204 -73.859007 \n",
"\n",
" Venue Category \n",
"0 Pizza Place \n",
"1 Fast Food Restaurant \n",
"2 Dessert Shop \n",
"3 Martial Arts Dojo \n",
"4 Donut Shop "
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toronto_venues.head()"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Venue Category\n",
"Coffee Shop 174\n",
"Café 98\n",
"Restaurant 71\n",
"Pizza Place 53\n",
"Park 51\n",
"Bakery 45\n",
"Italian Restaurant 45\n",
"Sandwich Place 42\n",
"Hotel 41\n",
"Japanese Restaurant 39\n",
"Clothing Store 34\n",
"Gym 33\n",
"Sushi Restaurant 30\n",
"Grocery Store 30\n",
"Bar 29\n",
"Fast Food Restaurant 27\n",
"American Restaurant 26\n",
"Pub 26\n",
"Bank 25\n",
"Pharmacy 23\n",
"Breakfast Spot 23\n",
"Thai Restaurant 21\n",
"Seafood Restaurant 20\n",
"Diner 19\n",
"Ice Cream Shop 19\n",
"Name: Neighborhood, dtype: int64"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Let's get only the venues that appears more than 25 times, so our clustering gets easier\n",
"venues_count = toronto_venues.groupby(\"Venue Category\")[\"Neighborhood\"].count().sort_values(ascending=False)\n",
"venues_count = venues_count.head(25)\n",
"venues_count "
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>Neighborhood Latitude</th>\n",
" <th>Neighborhood Longitude</th>\n",
" <th>Venue</th>\n",
" <th>Venue Latitude</th>\n",
" <th>Venue Longitude</th>\n",
" <th>Venue Category</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Domenick's Pizzeria</td>\n",
" <td>40.865576</td>\n",
" <td>-73.858124</td>\n",
" <td>Pizza Place</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>White Castle</td>\n",
" <td>40.866065</td>\n",
" <td>-73.862307</td>\n",
" <td>Fast Food Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>IHOP</td>\n",
" <td>40.865728</td>\n",
" <td>-73.862460</td>\n",
" <td>Breakfast Spot</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Domino's Pizza</td>\n",
" <td>40.866363</td>\n",
" <td>-73.861798</td>\n",
" <td>Pizza Place</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>Rite Aid</td>\n",
" <td>40.865949</td>\n",
" <td>-73.860922</td>\n",
" <td>Pharmacy</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood Neighborhood Latitude Neighborhood Longitude \\\n",
"0 Allerton 40.865788 -73.859319 \n",
"1 Allerton 40.865788 -73.859319 \n",
"5 Allerton 40.865788 -73.859319 \n",
"7 Allerton 40.865788 -73.859319 \n",
"9 Allerton 40.865788 -73.859319 \n",
"\n",
" Venue Venue Latitude Venue Longitude Venue Category \n",
"0 Domenick's Pizzeria 40.865576 -73.858124 Pizza Place \n",
"1 White Castle 40.866065 -73.862307 Fast Food Restaurant \n",
"5 IHOP 40.865728 -73.862460 Breakfast Spot \n",
"7 Domino's Pizza 40.866363 -73.861798 Pizza Place \n",
"9 Rite Aid 40.865949 -73.860922 Pharmacy "
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toronto_venues = toronto_venues[toronto_venues[\"Venue Category\"].isin(venues_count.index)]\n",
"toronto_venues.head()"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<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>American Restaurant</th>\n",
" <th>Bakery</th>\n",
" <th>Bank</th>\n",
" <th>Bar</th>\n",
" <th>Breakfast Spot</th>\n",
" <th>Café</th>\n",
" <th>Clothing Store</th>\n",
" <th>Coffee Shop</th>\n",
" <th>Diner</th>\n",
" <th>Fast Food Restaurant</th>\n",
" <th>Grocery Store</th>\n",
" <th>Gym</th>\n",
" <th>Hotel</th>\n",
" <th>Ice Cream Shop</th>\n",
" <th>Italian Restaurant</th>\n",
" <th>Japanese Restaurant</th>\n",
" <th>Park</th>\n",
" <th>Pharmacy</th>\n",
" <th>Pizza Place</th>\n",
" <th>Pub</th>\n",
" <th>Restaurant</th>\n",
" <th>Sandwich Place</th>\n",
" <th>Seafood Restaurant</th>\n",
" <th>Sushi Restaurant</th>\n",
" <th>Thai Restaurant</th>\n",
" <th>Neighborhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" American Restaurant Bakery Bank Bar Breakfast Spot Café \\\n",
"0 0 0 0 0 0 0 \n",
"1 0 0 0 0 0 0 \n",
"5 0 0 0 0 1 0 \n",
"7 0 0 0 0 0 0 \n",
"9 0 0 0 0 0 0 \n",
"\n",
" Clothing Store Coffee Shop Diner Fast Food Restaurant Grocery Store \\\n",
"0 0 0 0 0 0 \n",
"1 0 0 0 1 0 \n",
"5 0 0 0 0 0 \n",
"7 0 0 0 0 0 \n",
"9 0 0 0 0 0 \n",
"\n",
" Gym Hotel Ice Cream Shop Italian Restaurant Japanese Restaurant Park \\\n",
"0 0 0 0 0 0 0 \n",
"1 0 0 0 0 0 0 \n",
"5 0 0 0 0 0 0 \n",
"7 0 0 0 0 0 0 \n",
"9 0 0 0 0 0 0 \n",
"\n",
" Pharmacy Pizza Place Pub Restaurant Sandwich Place Seafood Restaurant \\\n",
"0 0 1 0 0 0 0 \n",
"1 0 0 0 0 0 0 \n",
"5 0 0 0 0 0 0 \n",
"7 0 1 0 0 0 0 \n",
"9 1 0 0 0 0 0 \n",
"\n",
" Sushi Restaurant Thai Restaurant Neighborhood \n",
"0 0 0 Allerton \n",
"1 0 0 Allerton \n",
"5 0 0 Allerton \n",
"7 0 0 Allerton \n",
"9 0 0 Allerton "
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Analyze Each Neighborhood\n",
"\n",
"# one hot encoding\n",
"toronto_onehot = pd.get_dummies(toronto_venues[['Venue Category']], prefix=\"\", prefix_sep=\"\")\n",
"\n",
"# add neighborhood column back to dataframe \n",
"toronto_onehot['Neighborhood'] = toronto_venues['Neighborhood'] \n",
"\n",
"# move neighborhood column to the first column\n",
"#fixed_columns = [toronto_onehot.columns[-1]] + list(toronto_onehot.columns[:-1])\n",
"#toronto_onehot = toronto_onehot[fixed_columns]\n",
"\n",
"toronto_onehot.head()"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>American Restaurant</th>\n",
" <th>Bakery</th>\n",
" <th>Bank</th>\n",
" <th>Bar</th>\n",
" <th>Breakfast Spot</th>\n",
" <th>Café</th>\n",
" <th>Clothing Store</th>\n",
" <th>Coffee Shop</th>\n",
" <th>Diner</th>\n",
" <th>Fast Food Restaurant</th>\n",
" <th>Grocery Store</th>\n",
" <th>Gym</th>\n",
" <th>Hotel</th>\n",
" <th>Ice Cream Shop</th>\n",
" <th>Italian Restaurant</th>\n",
" <th>Japanese Restaurant</th>\n",
" <th>Park</th>\n",
" <th>Pharmacy</th>\n",
" <th>Pizza Place</th>\n",
" <th>Pub</th>\n",
" <th>Restaurant</th>\n",
" <th>Sandwich Place</th>\n",
" <th>Seafood Restaurant</th>\n",
" <th>Sushi Restaurant</th>\n",
" <th>Thai Restaurant</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Allerton</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Allerton</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Allerton</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Allerton</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Allerton</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood American Restaurant Bakery Bank Bar Breakfast Spot Café \\\n",
"0 Allerton 0 0 0 0 0 0 \n",
"1 Allerton 0 0 0 0 0 0 \n",
"5 Allerton 0 0 0 0 1 0 \n",
"7 Allerton 0 0 0 0 0 0 \n",
"9 Allerton 0 0 0 0 0 0 \n",
"\n",
" Clothing Store Coffee Shop Diner Fast Food Restaurant Grocery Store \\\n",
"0 0 0 0 0 0 \n",
"1 0 0 0 1 0 \n",
"5 0 0 0 0 0 \n",
"7 0 0 0 0 0 \n",
"9 0 0 0 0 0 \n",
"\n",
" Gym Hotel Ice Cream Shop Italian Restaurant Japanese Restaurant Park \\\n",
"0 0 0 0 0 0 0 \n",
"1 0 0 0 0 0 0 \n",
"5 0 0 0 0 0 0 \n",
"7 0 0 0 0 0 0 \n",
"9 0 0 0 0 0 0 \n",
"\n",
" Pharmacy Pizza Place Pub Restaurant Sandwich Place Seafood Restaurant \\\n",
"0 0 1 0 0 0 0 \n",
"1 0 0 0 0 0 0 \n",
"5 0 0 0 0 0 0 \n",
"7 0 1 0 0 0 0 \n",
"9 1 0 0 0 0 0 \n",
"\n",
" Sushi Restaurant Thai Restaurant \n",
"0 0 0 \n",
"1 0 0 \n",
"5 0 0 \n",
"7 0 0 \n",
"9 0 0 "
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Moving the Neighborhood column to front:\n",
"\n",
"cols = toronto_onehot.columns.tolist()\n",
"cols.remove('Neighborhood') ## removing the column from the middle... \n",
"cols.insert(0,'Neighborhood') ## ...and reinserting it on the first position\n",
"toronto_onehot = toronto_onehot[cols]\n",
"toronto_onehot.head()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"(1044, 26)"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# And let's examine the new dataframe size.\n",
"toronto_onehot.shape"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>American Restaurant</th>\n",
" <th>Bakery</th>\n",
" <th>Bank</th>\n",
" <th>Bar</th>\n",
" <th>Breakfast Spot</th>\n",
" <th>Café</th>\n",
" <th>Clothing Store</th>\n",
" <th>Coffee Shop</th>\n",
" <th>Diner</th>\n",
" <th>Fast Food Restaurant</th>\n",
" <th>Grocery Store</th>\n",
" <th>Gym</th>\n",
" <th>Hotel</th>\n",
" <th>Ice Cream Shop</th>\n",
" <th>Italian Restaurant</th>\n",
" <th>Japanese Restaurant</th>\n",
" <th>Park</th>\n",
" <th>Pharmacy</th>\n",
" <th>Pizza Place</th>\n",
" <th>Pub</th>\n",
" <th>Restaurant</th>\n",
" <th>Sandwich Place</th>\n",
" <th>Seafood Restaurant</th>\n",
" <th>Sushi Restaurant</th>\n",
" <th>Thai Restaurant</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Agincourt</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.500</td>\n",
" <td>0.000000</td>\n",
" <td>0.5</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Alderwood / Long Branch</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.166667</td>\n",
" <td>0.000000</td>\n",
" <td>0.000</td>\n",
" <td>0.000</td>\n",
" <td>0.166667</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.333333</td>\n",
" <td>0.166667</td>\n",
" <td>0.000000</td>\n",
" <td>0.166667</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Allerton</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.125</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.125</td>\n",
" <td>0.125</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.125000</td>\n",
" <td>0.500000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Bathurst Manor / Wilson Heights / Downsview North</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.181818</td>\n",
" <td>0.0</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.181818</td>\n",
" <td>0.090909</td>\n",
" <td>0.000</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.090909</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.090909</td>\n",
" <td>0.090909</td>\n",
" <td>0.000000</td>\n",
" <td>0.090909</td>\n",
" <td>0.090909</td>\n",
" <td>0.0</td>\n",
" <td>0.090909</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bayview Village</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.333333</td>\n",
" <td>0.0</td>\n",
" <td>0.000</td>\n",
" <td>0.333333</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000</td>\n",
" <td>0.000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.333333</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood American Restaurant \\\n",
"0 Agincourt 0.0 \n",
"1 Alderwood / Long Branch 0.0 \n",
"2 Allerton 0.0 \n",
"3 Bathurst Manor / Wilson Heights / Downsview North 0.0 \n",
"4 Bayview Village 0.0 \n",
"\n",
" Bakery Bank Bar Breakfast Spot Café Clothing Store \\\n",
"0 0.0 0.000000 0.0 0.500 0.000000 0.5 \n",
"1 0.0 0.000000 0.0 0.000 0.000000 0.0 \n",
"2 0.0 0.000000 0.0 0.125 0.000000 0.0 \n",
"3 0.0 0.181818 0.0 0.000 0.000000 0.0 \n",
"4 0.0 0.333333 0.0 0.000 0.333333 0.0 \n",
"\n",
" Coffee Shop Diner Fast Food Restaurant Grocery Store Gym \\\n",
"0 0.000000 0.000000 0.000 0.000 0.000000 \n",
"1 0.166667 0.000000 0.000 0.000 0.166667 \n",
"2 0.000000 0.000000 0.125 0.125 0.000000 \n",
"3 0.181818 0.090909 0.000 0.000 0.000000 \n",
"4 0.000000 0.000000 0.000 0.000 0.000000 \n",
"\n",
" Hotel Ice Cream Shop Italian Restaurant Japanese Restaurant Park \\\n",
"0 0.0 0.000000 0.0 0.000000 0.0 \n",
"1 0.0 0.000000 0.0 0.000000 0.0 \n",
"2 0.0 0.000000 0.0 0.000000 0.0 \n",
"3 0.0 0.090909 0.0 0.000000 0.0 \n",
"4 0.0 0.000000 0.0 0.333333 0.0 \n",
"\n",
" Pharmacy Pizza Place Pub Restaurant Sandwich Place \\\n",
"0 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"1 0.000000 0.333333 0.166667 0.000000 0.166667 \n",
"2 0.125000 0.500000 0.000000 0.000000 0.000000 \n",
"3 0.090909 0.090909 0.000000 0.090909 0.090909 \n",
"4 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"\n",
" Seafood Restaurant Sushi Restaurant Thai Restaurant \n",
"0 0.0 0.000000 0.0 \n",
"1 0.0 0.000000 0.0 \n",
"2 0.0 0.000000 0.0 \n",
"3 0.0 0.090909 0.0 \n",
"4 0.0 0.000000 0.0 "
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Next, let's group rows by neighborhood and by taking the mean of the frequency\n",
"# of occurrence of each category\n",
"\n",
"toronto_grouped = toronto_onehot.groupby('Neighborhood').mean().reset_index()\n",
"toronto_grouped.head()"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"(86, 26)"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#### Let's confirm the new size\n",
"toronto_grouped.shape"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"----Agincourt----\n",
" venue freq\n",
"0 Breakfast Spot 0.5\n",
"1 Clothing Store 0.5\n",
"2 American Restaurant 0.0\n",
"3 Italian Restaurant 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Alderwood / Long Branch----\n",
" venue freq\n",
"0 Pizza Place 0.33\n",
"1 Sandwich Place 0.17\n",
"2 Pub 0.17\n",
"3 Coffee Shop 0.17\n",
"4 Gym 0.17\n",
"\n",
"\n",
"----Allerton----\n",
" venue freq\n",
"0 Pizza Place 0.50\n",
"1 Breakfast Spot 0.12\n",
"2 Fast Food Restaurant 0.12\n",
"3 Grocery Store 0.12\n",
"4 Pharmacy 0.12\n",
"\n",
"\n",
"----Bathurst Manor / Wilson Heights / Downsview North----\n",
" venue freq\n",
"0 Bank 0.18\n",
"1 Coffee Shop 0.18\n",
"2 Sushi Restaurant 0.09\n",
"3 Sandwich Place 0.09\n",
"4 Restaurant 0.09\n",
"\n",
"\n",
"----Bayview Village----\n",
" venue freq\n",
"0 Bank 0.33\n",
"1 Café 0.33\n",
"2 Japanese Restaurant 0.33\n",
"3 American Restaurant 0.00\n",
"4 Italian Restaurant 0.00\n",
"\n",
"\n",
"----Bedford Park / Lawrence Manor East----\n",
" venue freq\n",
"0 Sandwich Place 0.12\n",
"1 Restaurant 0.12\n",
"2 Coffee Shop 0.12\n",
"3 Italian Restaurant 0.12\n",
"4 American Restaurant 0.06\n",
"\n",
"\n",
"----Berczy Park----\n",
" venue freq\n",
"0 Coffee Shop 0.21\n",
"1 Bakery 0.08\n",
"2 Seafood Restaurant 0.08\n",
"3 Restaurant 0.08\n",
"4 Café 0.08\n",
"\n",
"\n",
"----Birch Cliff / Cliffside West----\n",
" venue freq\n",
"0 Café 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Brockton / Parkdale Village / Exhibition Place----\n",
" venue freq\n",
"0 Café 0.21\n",
"1 Breakfast Spot 0.14\n",
"2 Coffee Shop 0.14\n",
"3 Bakery 0.14\n",
"4 Bar 0.07\n",
"\n",
"\n",
"----Business reply mail Processing CentrE----\n",
" venue freq\n",
"0 Restaurant 0.25\n",
"1 Pizza Place 0.25\n",
"2 Fast Food Restaurant 0.25\n",
"3 Park 0.25\n",
"4 American Restaurant 0.00\n",
"\n",
"\n",
"----Caledonia-Fairbanks----\n",
" venue freq\n",
"0 Park 0.67\n",
"1 Bakery 0.33\n",
"2 American Restaurant 0.00\n",
"3 Ice Cream Shop 0.00\n",
"4 Sushi Restaurant 0.00\n",
"\n",
"\n",
"----Canada Post Gateway Processing Centre----\n",
" venue freq\n",
"0 Hotel 0.29\n",
"1 Coffee Shop 0.29\n",
"2 Sandwich Place 0.14\n",
"3 Gym 0.14\n",
"4 American Restaurant 0.14\n",
"\n",
"\n",
"----Cedarbrae----\n",
" venue freq\n",
"0 Thai Restaurant 0.33\n",
"1 Bank 0.33\n",
"2 Bakery 0.33\n",
"3 Italian Restaurant 0.00\n",
"4 Sushi Restaurant 0.00\n",
"\n",
"\n",
"----Central Bay Street----\n",
" venue freq\n",
"0 Coffee Shop 0.33\n",
"1 Sandwich Place 0.12\n",
"2 Italian Restaurant 0.12\n",
"3 Café 0.09\n",
"4 Japanese Restaurant 0.09\n",
"\n",
"\n",
"----Christie----\n",
" venue freq\n",
"0 Grocery Store 0.31\n",
"1 Café 0.23\n",
"2 Park 0.15\n",
"3 Restaurant 0.08\n",
"4 Coffee Shop 0.08\n",
"\n",
"\n",
"----Church and Wellesley----\n",
" venue freq\n",
"0 Sushi Restaurant 0.16\n",
"1 Coffee Shop 0.16\n",
"2 Japanese Restaurant 0.13\n",
"3 Restaurant 0.10\n",
"4 Hotel 0.06\n",
"\n",
"\n",
"----Clarks Corners / Tam O'Shanter / Sullivan----\n",
" venue freq\n",
"0 Pizza Place 0.25\n",
"1 Pharmacy 0.25\n",
"2 Thai Restaurant 0.12\n",
"3 Italian Restaurant 0.12\n",
"4 Bank 0.12\n",
"\n",
"\n",
"----Cliffside / Cliffcrest / Scarborough Village West----\n",
" venue freq\n",
"0 American Restaurant 1.0\n",
"1 Ice Cream Shop 0.0\n",
"2 Sushi Restaurant 0.0\n",
"3 Seafood Restaurant 0.0\n",
"4 Sandwich Place 0.0\n",
"\n",
"\n",
"----Commerce Court / Victoria Hotel----\n",
" venue freq\n",
"0 Coffee Shop 0.20\n",
"1 Café 0.11\n",
"2 Restaurant 0.11\n",
"3 Hotel 0.10\n",
"4 Gym 0.07\n",
"\n",
"\n",
"----Davisville----\n",
" venue freq\n",
"0 Sandwich Place 0.14\n",
"1 Pizza Place 0.14\n",
"2 Sushi Restaurant 0.09\n",
"3 Café 0.09\n",
"4 Coffee Shop 0.09\n",
"\n",
"\n",
"----Davisville North----\n",
" venue freq\n",
"0 Hotel 0.17\n",
"1 Breakfast Spot 0.17\n",
"2 Sandwich Place 0.17\n",
"3 Pizza Place 0.17\n",
"4 Park 0.17\n",
"\n",
"\n",
"----Del Ray / Mount Dennis / Keelsdale and Silverthorn----\n",
" venue freq\n",
"0 Bar 0.5\n",
"1 Sandwich Place 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Don Mills----\n",
" venue freq\n",
"0 Japanese Restaurant 0.17\n",
"1 Coffee Shop 0.17\n",
"2 Restaurant 0.17\n",
"3 Gym 0.17\n",
"4 Sandwich Place 0.08\n",
"\n",
"\n",
"----Downsview----\n",
" venue freq\n",
"0 Grocery Store 0.43\n",
"1 Park 0.29\n",
"2 Hotel 0.14\n",
"3 Bank 0.14\n",
"4 Italian Restaurant 0.00\n",
"\n",
"\n",
"----Dufferin / Dovercourt Village----\n",
" venue freq\n",
"0 Bakery 0.2\n",
"1 Pharmacy 0.2\n",
"2 Park 0.1\n",
"3 Bank 0.1\n",
"4 Bar 0.1\n",
"\n",
"\n",
"----East Toronto----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Eringate / Bloordale Gardens / Old Burnhamthorpe / Markland Wood----\n",
" venue freq\n",
"0 Café 0.25\n",
"1 Coffee Shop 0.25\n",
"2 Pizza Place 0.25\n",
"3 Pharmacy 0.25\n",
"4 American Restaurant 0.00\n",
"\n",
"\n",
"----Fairview / Henry Farm / Oriole----\n",
" venue freq\n",
"0 Clothing Store 0.26\n",
"1 Coffee Shop 0.16\n",
"2 Fast Food Restaurant 0.16\n",
"3 Restaurant 0.10\n",
"4 Bank 0.06\n",
"\n",
"\n",
"----First Canadian Place / Underground city----\n",
" venue freq\n",
"0 Coffee Shop 0.18\n",
"1 Café 0.15\n",
"2 Hotel 0.09\n",
"3 Restaurant 0.09\n",
"4 Gym 0.07\n",
"\n",
"\n",
"----Forest Hill North & West----\n",
" venue freq\n",
"0 Sushi Restaurant 0.5\n",
"1 Park 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Garden District-Ryerson----\n",
" venue freq\n",
"0 Clothing Store 0.21\n",
"1 Coffee Shop 0.19\n",
"2 Italian Restaurant 0.07\n",
"3 Café 0.07\n",
"4 Japanese Restaurant 0.07\n",
"\n",
"\n",
"----Glencairn----\n",
" venue freq\n",
"0 Pub 0.25\n",
"1 Japanese Restaurant 0.25\n",
"2 Italian Restaurant 0.25\n",
"3 Bakery 0.25\n",
"4 American Restaurant 0.00\n",
"\n",
"\n",
"----Golden Mile / Clairlea / Oakridge----\n",
" venue freq\n",
"0 Bakery 0.50\n",
"1 Ice Cream Shop 0.25\n",
"2 Park 0.25\n",
"3 American Restaurant 0.00\n",
"4 Sushi Restaurant 0.00\n",
"\n",
"\n",
"----Guildwood / Morningside / West Hill----\n",
" venue freq\n",
"0 Bank 0.5\n",
"1 Breakfast Spot 0.5\n",
"2 American Restaurant 0.0\n",
"3 Italian Restaurant 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Harbourfront East / Union Station / Toronto Islands----\n",
" venue freq\n",
"0 Coffee Shop 0.33\n",
"1 Hotel 0.10\n",
"2 Café 0.10\n",
"3 Restaurant 0.08\n",
"4 Park 0.05\n",
"\n",
"\n",
"----High Park / The Junction South----\n",
" venue freq\n",
"0 Thai Restaurant 0.17\n",
"1 Café 0.17\n",
"2 Park 0.08\n",
"3 Bar 0.08\n",
"4 Restaurant 0.08\n",
"\n",
"\n",
"----Humber Summit----\n",
" venue freq\n",
"0 Pizza Place 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----India Bazaar / The Beaches West----\n",
" venue freq\n",
"0 Pizza Place 0.14\n",
"1 Fast Food Restaurant 0.14\n",
"2 Park 0.14\n",
"3 Sushi Restaurant 0.07\n",
"4 Sandwich Place 0.07\n",
"\n",
"\n",
"----Kennedy Park / Ionview / East Birchmount Park----\n",
" venue freq\n",
"0 Coffee Shop 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Kensington Market / Chinatown / Grange Park----\n",
" venue freq\n",
"0 Café 0.22\n",
"1 Coffee Shop 0.13\n",
"2 Bakery 0.13\n",
"3 Park 0.09\n",
"4 Bar 0.09\n",
"\n",
"\n",
"----Kingsview Village / St. Phillips / Martin Grove Gardens / Richview Gardens----\n",
" venue freq\n",
"0 Sandwich Place 0.5\n",
"1 Pizza Place 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Lawrence Manor / Lawrence Heights----\n",
" venue freq\n",
"0 Clothing Store 0.75\n",
"1 Coffee Shop 0.25\n",
"2 American Restaurant 0.00\n",
"3 Italian Restaurant 0.00\n",
"4 Sushi Restaurant 0.00\n",
"\n",
"\n",
"----Lawrence Park----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Leaside----\n",
" venue freq\n",
"0 Coffee Shop 0.27\n",
"1 Bank 0.18\n",
"2 Sushi Restaurant 0.09\n",
"3 Breakfast Spot 0.09\n",
"4 Sandwich Place 0.09\n",
"\n",
"\n",
"----Little Portugal / Trinity----\n",
" venue freq\n",
"0 Bar 0.29\n",
"1 Café 0.12\n",
"2 Coffee Shop 0.12\n",
"3 Restaurant 0.12\n",
"4 Park 0.06\n",
"\n",
"\n",
"----Malvern / Rouge----\n",
" venue freq\n",
"0 Fast Food Restaurant 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Milliken / Agincourt North / Steeles East / L'Amoreaux East----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Mimico NW / The Queensway West / South of Bloor / Kingsway Park South West / Royal York South West----\n",
" venue freq\n",
"0 Sandwich Place 0.2\n",
"1 Fast Food Restaurant 0.2\n",
"2 Grocery Store 0.2\n",
"3 Gym 0.2\n",
"4 Bakery 0.2\n",
"\n",
"\n",
"----Moore Park / Summerhill East----\n",
" venue freq\n",
"0 Restaurant 0.5\n",
"1 Park 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----New Toronto / Mimico South / Humber Bay Shores----\n",
" venue freq\n",
"0 American Restaurant 0.12\n",
"1 Café 0.12\n",
"2 Restaurant 0.12\n",
"3 Pizza Place 0.12\n",
"4 Fast Food Restaurant 0.12\n",
"\n",
"\n",
"----North Park / Maple Leaf Park / Upwood Park----\n",
" venue freq\n",
"0 Park 0.5\n",
"1 Bakery 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----North Toronto West----\n",
" venue freq\n",
"0 Clothing Store 0.27\n",
"1 Coffee Shop 0.18\n",
"2 Park 0.09\n",
"3 Café 0.09\n",
"4 Diner 0.09\n",
"\n",
"\n",
"----Northwest----\n",
" venue freq\n",
"0 Bar 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Northwood Park / York University----\n",
" venue freq\n",
"0 Bar 0.5\n",
"1 Coffee Shop 0.5\n",
"2 American Restaurant 0.0\n",
"3 Italian Restaurant 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Parkdale / Roncesvalles----\n",
" venue freq\n",
"0 Breakfast Spot 0.29\n",
"1 Bank 0.14\n",
"2 Bar 0.14\n",
"3 Coffee Shop 0.14\n",
"4 Restaurant 0.14\n",
"\n",
"\n",
"----Parkview Hill / Woodbine Gardens----\n",
" venue freq\n",
"0 Pizza Place 0.4\n",
"1 Bank 0.2\n",
"2 Fast Food Restaurant 0.2\n",
"3 Pharmacy 0.2\n",
"4 American Restaurant 0.0\n",
"\n",
"\n",
"----Parkwoods----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Queen's Park / Ontario Provincial Government----\n",
" venue freq\n",
"0 Coffee Shop 0.42\n",
"1 Sushi Restaurant 0.11\n",
"2 Diner 0.11\n",
"3 Park 0.05\n",
"4 Bank 0.05\n",
"\n",
"\n",
"----Regent Park / Harbourfront----\n",
" venue freq\n",
"0 Coffee Shop 0.29\n",
"1 Park 0.12\n",
"2 Pub 0.12\n",
"3 Bakery 0.12\n",
"4 Breakfast Spot 0.08\n",
"\n",
"\n",
"----Richmond / Adelaide / King----\n",
" venue freq\n",
"0 Coffee Shop 0.20\n",
"1 Café 0.11\n",
"2 Restaurant 0.09\n",
"3 Gym 0.09\n",
"4 Hotel 0.07\n",
"\n",
"\n",
"----Rosedale----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Rouge Hill / Port Union / Highland Creek----\n",
" venue freq\n",
"0 Bar 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Runnymede / Swansea----\n",
" venue freq\n",
"0 Café 0.14\n",
"1 Coffee Shop 0.14\n",
"2 Sushi Restaurant 0.09\n",
"3 Diner 0.09\n",
"4 Restaurant 0.09\n",
"\n",
"\n",
"----Runnymede / The Junction North----\n",
" venue freq\n",
"0 Breakfast Spot 0.5\n",
"1 Grocery Store 0.5\n",
"2 American Restaurant 0.0\n",
"3 Italian Restaurant 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Scarborough Village----\n",
" venue freq\n",
"0 Grocery Store 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----South Steeles / Silverstone / Humbergate / Jamestown / Mount Olive / Beaumond Heights / Thistletown / Albion Gardens----\n",
" venue freq\n",
"0 Pizza Place 0.29\n",
"1 Grocery Store 0.29\n",
"2 Sandwich Place 0.14\n",
"3 Pharmacy 0.14\n",
"4 Fast Food Restaurant 0.14\n",
"\n",
"\n",
"----St. James Town----\n",
" venue freq\n",
"0 Coffee Shop 0.15\n",
"1 Café 0.15\n",
"2 American Restaurant 0.09\n",
"3 Restaurant 0.09\n",
"4 Italian Restaurant 0.06\n",
"\n",
"\n",
"----St. James Town / Cabbagetown----\n",
" venue freq\n",
"0 Café 0.12\n",
"1 Coffee Shop 0.12\n",
"2 Bakery 0.08\n",
"3 Restaurant 0.08\n",
"4 Pub 0.08\n",
"\n",
"\n",
"----Steeles West / L'Amoreaux West----\n",
" venue freq\n",
"0 Bank 0.12\n",
"1 Breakfast Spot 0.12\n",
"2 Sandwich Place 0.12\n",
"3 Coffee Shop 0.12\n",
"4 Fast Food Restaurant 0.12\n",
"\n",
"\n",
"----Stn A PO Boxes----\n",
" venue freq\n",
"0 Coffee Shop 0.21\n",
"1 Café 0.09\n",
"2 Hotel 0.06\n",
"3 Japanese Restaurant 0.06\n",
"4 Seafood Restaurant 0.06\n",
"\n",
"\n",
"----Studio District----\n",
" venue freq\n",
"0 Café 0.19\n",
"1 Coffee Shop 0.14\n",
"2 American Restaurant 0.10\n",
"3 Bakery 0.10\n",
"4 Seafood Restaurant 0.05\n",
"\n",
"\n",
"----Summerhill West / Rathnelly / South Hill / Forest Hill SE / Deer Park----\n",
" venue freq\n",
"0 Coffee Shop 0.22\n",
"1 Pub 0.22\n",
"2 American Restaurant 0.11\n",
"3 Bank 0.11\n",
"4 Sushi Restaurant 0.11\n",
"\n",
"\n",
"----The Annex / North Midtown / Yorkville----\n",
" venue freq\n",
"0 Sandwich Place 0.25\n",
"1 Café 0.25\n",
"2 Coffee Shop 0.17\n",
"3 Pub 0.08\n",
"4 Pizza Place 0.08\n",
"\n",
"\n",
"----The Beaches----\n",
" venue freq\n",
"0 Pub 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----The Danforth West / Riverdale----\n",
" venue freq\n",
"0 Coffee Shop 0.18\n",
"1 Italian Restaurant 0.18\n",
"2 Restaurant 0.12\n",
"3 Ice Cream Shop 0.12\n",
"4 American Restaurant 0.06\n",
"\n",
"\n",
"----Thorncliffe Park----\n",
" venue freq\n",
"0 Sandwich Place 0.18\n",
"1 Bank 0.09\n",
"2 Restaurant 0.09\n",
"3 Coffee Shop 0.09\n",
"4 Fast Food Restaurant 0.09\n",
"\n",
"\n",
"----Toronto Dominion Centre / Design Exchange----\n",
" venue freq\n",
"0 Coffee Shop 0.19\n",
"1 Hotel 0.15\n",
"2 Café 0.13\n",
"3 Restaurant 0.07\n",
"4 Seafood Restaurant 0.06\n",
"\n",
"\n",
"----University of Toronto / Harbord----\n",
" venue freq\n",
"0 Café 0.26\n",
"1 Japanese Restaurant 0.11\n",
"2 Bar 0.11\n",
"3 Restaurant 0.11\n",
"4 Bakery 0.11\n",
"\n",
"\n",
"----Victoria Village----\n",
" venue freq\n",
"0 Coffee Shop 0.5\n",
"1 Pizza Place 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----Westmount----\n",
" venue freq\n",
"0 Sandwich Place 0.33\n",
"1 Coffee Shop 0.33\n",
"2 Pizza Place 0.33\n",
"3 American Restaurant 0.00\n",
"4 Ice Cream Shop 0.00\n",
"\n",
"\n",
"----Weston----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Wexford / Maryvale----\n",
" venue freq\n",
"0 Breakfast Spot 0.33\n",
"1 Sandwich Place 0.33\n",
"2 Bakery 0.33\n",
"3 American Restaurant 0.00\n",
"4 Italian Restaurant 0.00\n",
"\n",
"\n",
"----Willowdale----\n",
" venue freq\n",
"0 Coffee Shop 0.14\n",
"1 Pizza Place 0.14\n",
"2 Sushi Restaurant 0.09\n",
"3 Café 0.09\n",
"4 Sandwich Place 0.09\n",
"\n",
"\n",
"----Woburn----\n",
" venue freq\n",
"0 Coffee Shop 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n",
"----Woodbine Heights----\n",
" venue freq\n",
"0 Pharmacy 0.5\n",
"1 Park 0.5\n",
"2 American Restaurant 0.0\n",
"3 Ice Cream Shop 0.0\n",
"4 Sushi Restaurant 0.0\n",
"\n",
"\n",
"----York Mills West----\n",
" venue freq\n",
"0 Park 1.0\n",
"1 American Restaurant 0.0\n",
"2 Ice Cream Shop 0.0\n",
"3 Sushi Restaurant 0.0\n",
"4 Seafood Restaurant 0.0\n",
"\n",
"\n"
]
}
],
"source": [
"#### Let's print each neighborhood along with the top 5 most common venues\n",
"\n",
"num_top_venues = 5\n",
"\n",
"for hood in toronto_grouped['Neighborhood']:\n",
" print(\"----\"+hood+\"----\")\n",
" temp = toronto_grouped[toronto_grouped['Neighborhood'] == hood].T.reset_index()\n",
" temp.columns = ['venue','freq']\n",
" temp = temp.iloc[1:]\n",
" temp['freq'] = temp['freq'].astype(float)\n",
" temp = temp.round({'freq': 2})\n",
" print(temp.sort_values('freq', ascending=False).reset_index(drop=True).head(num_top_venues))\n",
" print('\\n')"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
"# Let's put that into a *pandas* dataframe\n",
"# First, let's write a function to sort the venues in descending order.\n",
"\n",
"def return_most_common_venues(row, num_top_venues):\n",
" row_categories = row.iloc[1:]\n",
" row_categories_sorted = row_categories.sort_values(ascending=False)\n",
" \n",
" return row_categories_sorted.index.values[0:num_top_venues]"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Agincourt</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Clothing Store</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Diner</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Alderwood / Long Branch</td>\n",
" <td>Pizza Place</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Pub</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Gym</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Allerton</td>\n",
" <td>Pizza Place</td>\n",
" <td>Grocery Store</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Bathurst Manor / Wilson Heights / Downsview North</td>\n",
" <td>Bank</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Diner</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Restaurant</td>\n",
" <td>Pizza Place</td>\n",
" <td>Pharmacy</td>\n",
" <td>Ice Cream Shop</td>\n",
" <td>Sushi Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bayview Village</td>\n",
" <td>Bank</td>\n",
" <td>Café</td>\n",
" <td>Japanese Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Clothing Store</td>\n",
" <td>Coffee Shop</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood 1st Most Common Venue \\\n",
"0 Agincourt Breakfast Spot \n",
"1 Alderwood / Long Branch Pizza Place \n",
"2 Allerton Pizza Place \n",
"3 Bathurst Manor / Wilson Heights / Downsview North Bank \n",
"4 Bayview Village Bank \n",
"\n",
" 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n",
"0 Clothing Store Thai Restaurant Gym \n",
"1 Sandwich Place Pub Coffee Shop \n",
"2 Grocery Store Breakfast Spot Pharmacy \n",
"3 Coffee Shop Diner Sandwich Place \n",
"4 Café Japanese Restaurant Thai Restaurant \n",
"\n",
" 5th Most Common Venue 6th Most Common Venue 7th Most Common Venue \\\n",
"0 Bakery Bank Bar \n",
"1 Gym Thai Restaurant Fast Food Restaurant \n",
"2 Fast Food Restaurant Thai Restaurant Bakery \n",
"3 Restaurant Pizza Place Pharmacy \n",
"4 Gym Bakery Bar \n",
"\n",
" 8th Most Common Venue 9th Most Common Venue 10th Most Common Venue \n",
"0 Café Coffee Shop Diner \n",
"1 Bakery Bank Bar \n",
"2 Bank Bar Café \n",
"3 Ice Cream Shop Sushi Restaurant Thai Restaurant \n",
"4 Breakfast Spot Clothing Store Coffee Shop "
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now let's create the new dataframe and display the top 10 venues for each neighborhood.\n",
"\n",
"num_top_venues = 10\n",
"\n",
"indicators = ['st', 'nd', 'rd']\n",
"\n",
"# create columns according to number of top venues\n",
"columns = ['Neighborhood']\n",
"for ind in np.arange(num_top_venues):\n",
" try:\n",
" columns.append('{}{} Most Common Venue'.format(ind+1, indicators[ind]))\n",
" except:\n",
" columns.append('{}th Most Common Venue'.format(ind+1))\n",
"\n",
"# create a new dataframe\n",
"neighborhoods_venues_sorted = pd.DataFrame(columns=columns)\n",
"neighborhoods_venues_sorted['Neighborhood'] = toronto_grouped['Neighborhood']\n",
"\n",
"for ind in np.arange(toronto_grouped.shape[0]):\n",
" neighborhoods_venues_sorted.iloc[ind, 1:] = return_most_common_venues(toronto_grouped.iloc[ind, :], num_top_venues)\n",
"\n",
"neighborhoods_venues_sorted.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a id='item4'></a>"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(86, 11)"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"neighborhoods_venues_sorted.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cluster Neighborhoods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Running *k*-means to cluster the neighborhood into 5 clusters."
]
},
{
"cell_type": "code",
"execution_count": 138,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([5, 0, 0, 5, 5, 5, 5, 3, 5, 1, 2, 5, 5, 5, 5, 5, 1, 5, 5, 5, 1, 1,\n",
" 5, 1, 5, 4, 5, 5, 5, 2, 5, 5, 2, 1, 5, 5, 0, 1, 8, 5, 0, 5, 4, 5,\n",
" 5, 1, 4, 1, 2, 5, 2, 5, 7, 5, 5, 0, 4, 5, 5, 5, 4, 7, 5, 1, 1, 1,\n",
" 5, 5, 1, 5, 5, 5, 5, 6, 5, 1, 5, 5, 0, 0, 4, 1, 5, 8, 2, 4],\n",
" dtype=int32)"
]
},
"execution_count": 138,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# set number of clusters\n",
"kclusters = 9\n",
"\n",
"toronto_grouped_clustering = toronto_grouped.drop('Neighborhood', 1)\n",
"\n",
"# run k-means clustering\n",
"kmeans = KMeans(n_clusters=kclusters, random_state=0).fit(toronto_grouped_clustering)\n",
"\n",
"# check cluster labels generated for each row in the dataframe\n",
"kmeans.labels_"
]
},
{
"cell_type": "code",
"execution_count": 139,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Cluster Labels</th>\n",
" <th>Neighborhood</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>Agincourt</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Clothing Store</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Diner</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>Alderwood / Long Branch</td>\n",
" <td>Pizza Place</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Pub</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Gym</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" <td>Pizza Place</td>\n",
" <td>Grocery Store</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>Bathurst Manor / Wilson Heights / Downsview North</td>\n",
" <td>Bank</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Diner</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Restaurant</td>\n",
" <td>Pizza Place</td>\n",
" <td>Pharmacy</td>\n",
" <td>Ice Cream Shop</td>\n",
" <td>Sushi Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>Bayview Village</td>\n",
" <td>Bank</td>\n",
" <td>Café</td>\n",
" <td>Japanese Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Clothing Store</td>\n",
" <td>Coffee Shop</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Cluster Labels Neighborhood \\\n",
"0 0 Agincourt \n",
"1 0 Alderwood / Long Branch \n",
"2 0 Allerton \n",
"3 0 Bathurst Manor / Wilson Heights / Downsview North \n",
"4 0 Bayview Village \n",
"\n",
" 1st Most Common Venue 2nd Most Common Venue 3rd Most Common Venue \\\n",
"0 Breakfast Spot Clothing Store Thai Restaurant \n",
"1 Pizza Place Sandwich Place Pub \n",
"2 Pizza Place Grocery Store Breakfast Spot \n",
"3 Bank Coffee Shop Diner \n",
"4 Bank Café Japanese Restaurant \n",
"\n",
" 4th Most Common Venue 5th Most Common Venue 6th Most Common Venue \\\n",
"0 Gym Bakery Bank \n",
"1 Coffee Shop Gym Thai Restaurant \n",
"2 Pharmacy Fast Food Restaurant Thai Restaurant \n",
"3 Sandwich Place Restaurant Pizza Place \n",
"4 Thai Restaurant Gym Bakery \n",
"\n",
" 7th Most Common Venue 8th Most Common Venue 9th Most Common Venue \\\n",
"0 Bar Café Coffee Shop \n",
"1 Fast Food Restaurant Bakery Bank \n",
"2 Bakery Bank Bar \n",
"3 Pharmacy Ice Cream Shop Sushi Restaurant \n",
"4 Bar Breakfast Spot Clothing Store \n",
"\n",
" 10th Most Common Venue \n",
"0 Diner \n",
"1 Bar \n",
"2 Café \n",
"3 Thai Restaurant \n",
"4 Coffee Shop "
]
},
"execution_count": 139,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"neighborhoods_venues_sorted.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 140,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(86, 25)"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toronto_grouped_clustering.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create a new dataframe that includes the cluster as well as the top 10 venues for each neighborhood."
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [],
"source": [
"if 'Cluster Labels' in neighborhoods_venues_sorted:\n",
" #neighborhoods_venues_sorted['Cluster Labels'] == kmeans.labels_\n",
" neighborhoods_venues_sorted.drop(columns=['Cluster Labels'],inplace = True)\n",
" neighborhoods_venues_sorted.insert(0, 'Cluster Labels', kmeans.labels_)\n",
"else:\n",
" neighborhoods_venues_sorted.insert(0, 'Cluster Labels', kmeans.labels_)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 142,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Cluster Labels</th>\n",
" <th>Neighborhood</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5</td>\n",
" <td>Agincourt</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Clothing Store</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Diner</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>Alderwood / Long Branch</td>\n",
" <td>Pizza Place</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Pub</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Gym</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>Allerton</td>\n",
" <td>Pizza Place</td>\n",
" <td>Grocery Store</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>5</td>\n",
" <td>Bathurst Manor / Wilson Heights / Downsview North</td>\n",
" <td>Bank</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Diner</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Restaurant</td>\n",
" <td>Pizza Place</td>\n",
" <td>Pharmacy</td>\n",
" <td>Ice Cream Shop</td>\n",
" <td>Sushi Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>Bayview Village</td>\n",
" <td>Bank</td>\n",
" <td>Café</td>\n",
" <td>Japanese Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Clothing Store</td>\n",
" <td>Coffee Shop</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Cluster Labels Neighborhood \\\n",
"0 5 Agincourt \n",
"1 0 Alderwood / Long Branch \n",
"2 0 Allerton \n",
"3 5 Bathurst Manor / Wilson Heights / Downsview North \n",
"4 5 Bayview Village \n",
"\n",
" 1st Most Common Venue 2nd Most Common Venue 3rd Most Common Venue \\\n",
"0 Breakfast Spot Clothing Store Thai Restaurant \n",
"1 Pizza Place Sandwich Place Pub \n",
"2 Pizza Place Grocery Store Breakfast Spot \n",
"3 Bank Coffee Shop Diner \n",
"4 Bank Café Japanese Restaurant \n",
"\n",
" 4th Most Common Venue 5th Most Common Venue 6th Most Common Venue \\\n",
"0 Gym Bakery Bank \n",
"1 Coffee Shop Gym Thai Restaurant \n",
"2 Pharmacy Fast Food Restaurant Thai Restaurant \n",
"3 Sandwich Place Restaurant Pizza Place \n",
"4 Thai Restaurant Gym Bakery \n",
"\n",
" 7th Most Common Venue 8th Most Common Venue 9th Most Common Venue \\\n",
"0 Bar Café Coffee Shop \n",
"1 Fast Food Restaurant Bakery Bank \n",
"2 Bakery Bank Bar \n",
"3 Pharmacy Ice Cream Shop Sushi Restaurant \n",
"4 Bar Breakfast Spot Clothing Store \n",
"\n",
" 10th Most Common Venue \n",
"0 Diner \n",
"1 Bar \n",
"2 Café \n",
"3 Thai Restaurant \n",
"4 Coffee Shop "
]
},
"execution_count": 142,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"neighborhoods_venues_sorted.head()"
]
},
{
"cell_type": "code",
"execution_count": 143,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# add clustering labels\n",
"#neighborhoods_venues_sorted.insert(0, 'Cluster Labels', kmeans.labels_)\n"
]
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [],
"source": [
"toronto_merged = Toronto_Neighb\n",
"\n",
"# merge toronto_grouped with toronto_data to add latitude/longitude for each neighborhood\n",
"toronto_merged = toronto_merged.join(neighborhoods_venues_sorted.set_index('Neighborhood'), on='Neighborhood')\n"
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [],
"source": [
"toronto_merged.dropna(how='any', inplace = True)\n",
"toronto_merged[\"Cluster Labels\"] = toronto_merged[\"Cluster Labels\"].astype(int)"
]
},
{
"cell_type": "code",
"execution_count": 146,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Cluster Labels</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" <td>18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude Longitude city Postalcode \\\n",
"Cluster Labels \n",
"0 7 7 7 7 7 7 \n",
"1 18 18 18 18 18 18 \n",
"2 6 6 6 6 6 6 \n",
"3 1 1 1 1 1 1 \n",
"4 7 7 7 7 7 7 \n",
"5 47 47 47 47 47 47 \n",
"6 1 1 1 1 1 1 \n",
"7 2 2 2 2 2 2 \n",
"8 2 2 2 2 2 2 \n",
"\n",
" 1st Most Common Venue 2nd Most Common Venue \\\n",
"Cluster Labels \n",
"0 7 7 \n",
"1 18 18 \n",
"2 6 6 \n",
"3 1 1 \n",
"4 7 7 \n",
"5 47 47 \n",
"6 1 1 \n",
"7 2 2 \n",
"8 2 2 \n",
"\n",
" 3rd Most Common Venue 4th Most Common Venue \\\n",
"Cluster Labels \n",
"0 7 7 \n",
"1 18 18 \n",
"2 6 6 \n",
"3 1 1 \n",
"4 7 7 \n",
"5 47 47 \n",
"6 1 1 \n",
"7 2 2 \n",
"8 2 2 \n",
"\n",
" 5th Most Common Venue 6th Most Common Venue \\\n",
"Cluster Labels \n",
"0 7 7 \n",
"1 18 18 \n",
"2 6 6 \n",
"3 1 1 \n",
"4 7 7 \n",
"5 47 47 \n",
"6 1 1 \n",
"7 2 2 \n",
"8 2 2 \n",
"\n",
" 7th Most Common Venue 8th Most Common Venue \\\n",
"Cluster Labels \n",
"0 7 7 \n",
"1 18 18 \n",
"2 6 6 \n",
"3 1 1 \n",
"4 7 7 \n",
"5 47 47 \n",
"6 1 1 \n",
"7 2 2 \n",
"8 2 2 \n",
"\n",
" 9th Most Common Venue 10th Most Common Venue \n",
"Cluster Labels \n",
"0 7 7 \n",
"1 18 18 \n",
"2 6 6 \n",
"3 1 1 \n",
"4 7 7 \n",
"5 47 47 \n",
"6 1 1 \n",
"7 2 2 \n",
"8 2 2 "
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toronto_merged.groupby(\"Cluster Labels\").count()"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" <th>Cluster Labels</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>298</th>\n",
" <td>Bronx</td>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Grocery Store</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>43.753259</td>\n",
" <td>-79.329656</td>\n",
" <td>TO</td>\n",
" <td>M3A</td>\n",
" <td>4</td>\n",
" <td>Park</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Clothing Store</td>\n",
" <td>Coffee Shop</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>North York</td>\n",
" <td>Victoria Village</td>\n",
" <td>43.725882</td>\n",
" <td>-79.315572</td>\n",
" <td>TO</td>\n",
" <td>M4A</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Clothing Store</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park / Harbourfront</td>\n",
" <td>43.654260</td>\n",
" <td>-79.360636</td>\n",
" <td>TO</td>\n",
" <td>M5A</td>\n",
" <td>5</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Bakery</td>\n",
" <td>Pub</td>\n",
" <td>Park</td>\n",
" <td>Restaurant</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Bank</td>\n",
" <td>Ice Cream Shop</td>\n",
" <td>Thai Restaurant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor / Lawrence Heights</td>\n",
" <td>43.718518</td>\n",
" <td>-79.464763</td>\n",
" <td>TO</td>\n",
" <td>M6A</td>\n",
" <td>5</td>\n",
" <td>Clothing Store</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Diner</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude \\\n",
"298 Bronx Allerton 40.865788 \n",
"0 North York Parkwoods 43.753259 \n",
"1 North York Victoria Village 43.725882 \n",
"2 Downtown Toronto Regent Park / Harbourfront 43.654260 \n",
"3 North York Lawrence Manor / Lawrence Heights 43.718518 \n",
"\n",
" Longitude city Postalcode Cluster Labels 1st Most Common Venue \\\n",
"298 -73.859319 NY NY 0 Pizza Place \n",
"0 -79.329656 TO M3A 4 Park \n",
"1 -79.315572 TO M4A 0 Pizza Place \n",
"2 -79.360636 TO M5A 5 Coffee Shop \n",
"3 -79.464763 TO M6A 5 Clothing Store \n",
"\n",
" 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n",
"298 Grocery Store Breakfast Spot Pharmacy \n",
"0 Thai Restaurant Gym Bakery \n",
"1 Coffee Shop Thai Restaurant Gym \n",
"2 Bakery Pub Park \n",
"3 Coffee Shop Thai Restaurant Gym \n",
"\n",
" 5th Most Common Venue 6th Most Common Venue 7th Most Common Venue \\\n",
"298 Fast Food Restaurant Thai Restaurant Bakery \n",
"0 Bank Bar Breakfast Spot \n",
"1 Bakery Bank Bar \n",
"2 Restaurant Breakfast Spot Café \n",
"3 Bakery Bank Bar \n",
"\n",
" 8th Most Common Venue 9th Most Common Venue 10th Most Common Venue \n",
"298 Bank Bar Café \n",
"0 Café Clothing Store Coffee Shop \n",
"1 Breakfast Spot Café Clothing Store \n",
"2 Bank Ice Cream Shop Thai Restaurant \n",
"3 Breakfast Spot Café Diner "
]
},
"execution_count": 147,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toronto_merged.head()"
]
},
{
"cell_type": "code",
"execution_count": 148,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Borough</th>\n",
" <th>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Longitude</th>\n",
" <th>city</th>\n",
" <th>Postalcode</th>\n",
" <th>Cluster Labels</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>298</th>\n",
" <td>Bronx</td>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>-73.859319</td>\n",
" <td>NY</td>\n",
" <td>NY</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Grocery Store</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighborhood Latitude Longitude city Postalcode \\\n",
"298 Bronx Allerton 40.865788 -73.859319 NY NY \n",
"\n",
" Cluster Labels 1st Most Common Venue 2nd Most Common Venue \\\n",
"298 0 Pizza Place Grocery Store \n",
"\n",
" 3rd Most Common Venue 4th Most Common Venue 5th Most Common Venue \\\n",
"298 Breakfast Spot Pharmacy Fast Food Restaurant \n",
"\n",
" 6th Most Common Venue 7th Most Common Venue 8th Most Common Venue \\\n",
"298 Thai Restaurant Bakery Bank \n",
"\n",
" 9th Most Common Venue 10th Most Common Venue \n",
"298 Bar Café "
]
},
"execution_count": 148,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Get the NY Cluster\n",
"toronto_merged[toronto_merged.city==\"NY\"]"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 149,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"NY_cluster = toronto_merged[toronto_merged.city==\"NY\"].iloc[0,toronto_merged.columns.tolist().index('Cluster Labels')]\n",
"NY_cluster"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Cluster for the Accidental Tourist: you may now choose the Toronto Neighborhood that is most similiar with your NY Neighborhood, and book your ticket and reservations :)"
]
},
{
"cell_type": "code",
"execution_count": 150,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>Neighborhood</th>\n",
" <th>Latitude</th>\n",
" <th>Postalcode</th>\n",
" <th>Cluster Labels</th>\n",
" <th>1st Most Common Venue</th>\n",
" <th>2nd Most Common Venue</th>\n",
" <th>3rd Most Common Venue</th>\n",
" <th>4th Most Common Venue</th>\n",
" <th>5th Most Common Venue</th>\n",
" <th>6th Most Common Venue</th>\n",
" <th>7th Most Common Venue</th>\n",
" <th>8th Most Common Venue</th>\n",
" <th>9th Most Common Venue</th>\n",
" <th>10th Most Common Venue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>298</th>\n",
" <td>Allerton</td>\n",
" <td>40.865788</td>\n",
" <td>NY</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Grocery Store</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Victoria Village</td>\n",
" <td>43.725882</td>\n",
" <td>M4A</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Clothing Store</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Parkview Hill / Woodbine Gardens</td>\n",
" <td>43.706397</td>\n",
" <td>M4B</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Bank</td>\n",
" <td>Pharmacy</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Grocery Store</td>\n",
" <td>Bakery</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>Humber Summit</td>\n",
" <td>43.756303</td>\n",
" <td>M9L</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Gym</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Clothing Store</td>\n",
" <td>Coffee Shop</td>\n",
" </tr>\n",
" <tr>\n",
" <th>70</th>\n",
" <td>Westmount</td>\n",
" <td>43.696319</td>\n",
" <td>M9P</td>\n",
" <td>0</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Pizza Place</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Grocery Store</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" </tr>\n",
" <tr>\n",
" <th>77</th>\n",
" <td>Kingsview Village / St. Phillips / Martin Grov...</td>\n",
" <td>43.688905</td>\n",
" <td>M9R</td>\n",
" <td>0</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Pizza Place</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Grocery Store</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" <td>Breakfast Spot</td>\n",
" <td>Café</td>\n",
" <td>Clothing Store</td>\n",
" </tr>\n",
" <tr>\n",
" <th>93</th>\n",
" <td>Alderwood / Long Branch</td>\n",
" <td>43.602414</td>\n",
" <td>M8W</td>\n",
" <td>0</td>\n",
" <td>Pizza Place</td>\n",
" <td>Sandwich Place</td>\n",
" <td>Pub</td>\n",
" <td>Coffee Shop</td>\n",
" <td>Gym</td>\n",
" <td>Thai Restaurant</td>\n",
" <td>Fast Food Restaurant</td>\n",
" <td>Bakery</td>\n",
" <td>Bank</td>\n",
" <td>Bar</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Neighborhood Latitude Postalcode \\\n",
"298 Allerton 40.865788 NY \n",
"1 Victoria Village 43.725882 M4A \n",
"8 Parkview Hill / Woodbine Gardens 43.706397 M4B \n",
"50 Humber Summit 43.756303 M9L \n",
"70 Westmount 43.696319 M9P \n",
"77 Kingsview Village / St. Phillips / Martin Grov... 43.688905 M9R \n",
"93 Alderwood / Long Branch 43.602414 M8W \n",
"\n",
" Cluster Labels 1st Most Common Venue 2nd Most Common Venue \\\n",
"298 0 Pizza Place Grocery Store \n",
"1 0 Pizza Place Coffee Shop \n",
"8 0 Pizza Place Bank \n",
"50 0 Pizza Place Thai Restaurant \n",
"70 0 Sandwich Place Pizza Place \n",
"77 0 Sandwich Place Pizza Place \n",
"93 0 Pizza Place Sandwich Place \n",
"\n",
" 3rd Most Common Venue 4th Most Common Venue 5th Most Common Venue \\\n",
"298 Breakfast Spot Pharmacy Fast Food Restaurant \n",
"1 Thai Restaurant Gym Bakery \n",
"8 Pharmacy Fast Food Restaurant Thai Restaurant \n",
"50 Gym Bakery Bank \n",
"70 Coffee Shop Thai Restaurant Grocery Store \n",
"77 Thai Restaurant Grocery Store Bakery \n",
"93 Pub Coffee Shop Gym \n",
"\n",
" 6th Most Common Venue 7th Most Common Venue 8th Most Common Venue \\\n",
"298 Thai Restaurant Bakery Bank \n",
"1 Bank Bar Breakfast Spot \n",
"8 Grocery Store Bakery Bar \n",
"50 Bar Breakfast Spot Café \n",
"70 Bakery Bank Bar \n",
"77 Bank Bar Breakfast Spot \n",
"93 Thai Restaurant Fast Food Restaurant Bakery \n",
"\n",
" 9th Most Common Venue 10th Most Common Venue \n",
"298 Bar Café \n",
"1 Café Clothing Store \n",
"8 Breakfast Spot Café \n",
"50 Clothing Store Coffee Shop \n",
"70 Breakfast Spot Café \n",
"77 Café Clothing Store \n",
"93 Bank Bar "
]
},
"execution_count": 150,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toronto_merged.loc[toronto_merged['Cluster Labels'] == NY_cluster, toronto_merged.columns[[1] + [2] + list(range(5, toronto_merged.shape[1]))]]"
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The geograpical coordinate of Toronto are 43.6534817, -79.3839347.\n"
]
}
],
"source": [
"address = 'Toronto, TO'\n",
"\n",
"geolocator = Nominatim(user_agent=\"ny_explorer\")\n",
"location = geolocator.geocode(address)\n",
"latitude = location.latitude\n",
"longitude = location.longitude\n",
"print('The geograpical coordinate of Toronto are {}, {}.'.format(latitude, longitude))"
]
},
{
"cell_type": "code",
"execution_count": 152,
"metadata": {},
"outputs": [
{
"data": {
"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 src=\"about:blank\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" data-html=PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVMgPSBmYWxzZTsgTF9OT19UT1VDSCA9IGZhbHNlOyBMX0RJU0FCTEVfM0QgPSBmYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS4yLjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjExLjEvanF1ZXJ5Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS4yLjAvZGlzdC9sZWFmbGV0LmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3RzdHJhcC8zLjIuMC9jc3MvYm9vdHN0cmFwLm1pbi5jc3MiLz4KICAgIDxsaW5rIHJlbD0ic3R5bGVzaGVldCIgaHJlZj0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvY3NzL2Jvb3RzdHJhcC10aGVtZS5taW4uY3NzIi8+CiAgICA8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9Imh0dHBzOi8vbWF4Y2RuLmJvb3RzdHJhcGNkbi5jb20vZm9udC1hd2Vzb21lLzQuNi4zL2Nzcy9mb250LWF3ZXNvbWUubWluLmNzcyIvPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9MZWFmbGV0LmF3ZXNvbWUtbWFya2Vycy8yLjAuMi9sZWFmbGV0LmF3ZXNvbWUtbWFya2Vycy5jc3MiLz4KICAgIDxsaW5rIHJlbD0ic3R5bGVzaGVldCIgaHJlZj0iaHR0cHM6Ly9yYXdnaXQuY29tL3B5dGhvbi12aXN1YWxpemF0aW9uL2ZvbGl1bS9tYXN0ZXIvZm9saXVtL3RlbXBsYXRlcy9sZWFmbGV0LmF3ZXNvbWUucm90YXRlLmNzcyIvPgogICAgPHN0eWxlPmh0bWwsIGJvZHkge3dpZHRoOiAxMDAlO2hlaWdodDogMTAwJTttYXJnaW46IDA7cGFkZGluZzogMDt9PC9zdHlsZT4KICAgIDxzdHlsZT4jbWFwIHtwb3NpdGlvbjphYnNvbHV0ZTt0b3A6MDtib3R0b206MDtyaWdodDowO2xlZnQ6MDt9PC9zdHlsZT4KICAgIAogICAgICAgICAgICA8c3R5bGU+ICNtYXBfZjc1NTU2YTk3MzRkNGJlZjkyMzc2MmVlNTE5ZWEwNTggewogICAgICAgICAgICAgICAgcG9zaXRpb24gOiByZWxhdGl2ZTsKICAgICAgICAgICAgICAgIHdpZHRoIDogMTAwLjAlOwogICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICBsZWZ0OiAwLjAlOwogICAgICAgICAgICAgICAgdG9wOiAwLjAlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICA8L3N0eWxlPgogICAgICAgIAo8L2hlYWQ+Cjxib2R5PiAgICAKICAgIAogICAgICAgICAgICA8ZGl2IGNsYXNzPSJmb2xpdW0tbWFwIiBpZD0ibWFwX2Y3NTU1NmE5NzM0ZDRiZWY5MjM3NjJlZTUxOWVhMDU4IiA+PC9kaXY+CiAgICAgICAgCjwvYm9keT4KPHNjcmlwdD4gICAgCiAgICAKCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgdmFyIGJvdW5kcyA9IG51bGw7CiAgICAgICAgICAgIAoKICAgICAgICAgICAgdmFyIG1hcF9mNzU1NTZhOTczNGQ0YmVmOTIzNzYyZWU1MTllYTA1OCA9IEwubWFwKAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ21hcF9mNzU1NTZhOTczNGQ0YmVmOTIzNzYyZWU1MTllYTA1OCcsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7Y2VudGVyOiBbNDMuNjUzNDgxNywtNzkuMzgzOTM0N10sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB6b29tOiAxMSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGF5ZXJzOiBbXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmxkQ29weUp1bXA6IGZhbHNlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIHRpbGVfbGF5ZXJfZjY1ZmVlYzFiYzNhNGNhOGFhNmY2M2YyNzkxNmQ1ZTAgPSBMLnRpbGVMYXllcigKICAgICAgICAgICAgICAgICdodHRwczovL3tzfS50aWxlLm9wZW5zdHJlZXRtYXAub3JnL3t6fS97eH0ve3l9LnBuZycsCiAgICAgICAgICAgICAgICB7CiAgImF0dHJpYnV0aW9uIjogbnVsbCwKICAiZGV0ZWN0UmV0aW5hIjogZmFsc2UsCiAgIm1heFpvb20iOiAxOCwKICAibWluWm9vbSI6IDEsCiAgIm5vV3JhcCI6IGZhbHNlLAogICJzdWJkb21haW5zIjogImFiYyIKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfZjc1NTU2YTk3MzRkNGJlZjkyMzc2MmVlNTE5ZWEwNTgpOwogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBjaXJjbGVfbWFya2VyXzA5MmFjY2NjY2VlZDQzOGVhYWVmMTYxY2I5YTliNDU4ID0gTC5jaXJjbGVNYXJrZXIoCiAgICAgICAgICAgICAgICBbNDAuODY1Nzg3ODc4MDI5ODIsLTczLjg1OTMxODYzMjIxNjQ3XSwKICAgICAgICAgICAgICAgIHsKICAiYnViYmxpbmdNb3VzZUV2ZW50cyI6IHRydWUsCiAgImNvbG9yIjogIiNmZjAwMDAiLAogICJkYXNoQXJyYXkiOiBudWxsLAogICJkYXNoT2Zmc2V0IjogbnVsbCwKICAiZmlsbCI6IHRydWUsCiAgImZpbGxDb2xvciI6ICIjZmYwMDAwIiwKICAiZmlsbE9wYWNpdHkiOiAwLjcsCiAgImZpbGxSdWxlIjogImV2ZW5vZGQiLAogICJsaW5lQ2FwIjogInJvdW5kIiwKICAibGluZUpvaW4iOiAicm91bmQiLAogICJvcGFjaXR5IjogMS4wLAogICJyYWRpdXMiOiA1LAogICJzdHJva2UiOiB0cnVlLAogICJ3ZWlnaHQiOiAzCn0KICAgICAgICAgICAgICAgICkuYWRkVG8obWFwX2Y3NTU1NmE5NzM0ZDRiZWY5MjM3NjJlZTUxOWVhMDU4KTsKICAgICAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIHBvcHVwXzczMzMyYTM5M2JiZjRjNDU5ZTZlODcyYTU3YWM1ZGVjID0gTC5wb3B1cCh7bWF4V2lkdGg6ICczMDAnfSk7CgogICAgICAgICAgICAKICAgICAgICAgICAgICAgIHZhciBodG1sXzNhYTI1NGU5OWRjYzQxNjVhNjJkOTIzMGU0ZjUxODY3ID0gJCgnPGRpdiBpZD0iaHRtbF8zYWEyNTRlOTlkY2M0MTY1YTYyZDkyMzBlNGY1MTg2NyIgc3R5bGU9IndpZHRoOiAxMDAuMCU7IGhlaWdodDogMTAwLjAlOyI+QWxsZXJ0b24gQ2x1c3RlciAwPC9kaXY+JylbMF07CiAgICAgICAgICAgICAgICBwb3B1cF83MzMzMmEzOTNiYmY0YzQ1OWU2ZTg3MmE1N2FjNWRlYy5zZXRDb250ZW50KGh0bWxfM2FhMjU0ZTk5ZGNjNDE2NWE2MmQ5MjMwZTRmNTE4NjcpOwogICAgICAgICAgICAKCiAgICAgICAgICAgIGNpcmNsZV9tYXJrZXJfMDkyYWNjY2NjZWVkNDM4ZWFhZWYxNjFjYjlhOWI0NTguYmluZFBvcHVwKHBvcHVwXzczMzMyYTM5M2JiZjRjNDU5ZTZlODcyYTU3YWM1ZGVjKTsKCiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBjaXJjbGVfbWFya2VyX2I3YjFlM2FlMjcwMDRlYjU5MzFhOTcyYmRjNGExNWFlID0gTC5jaXJjbGVNYXJrZXIoCiAgICAgICAgICAgICAgICBbNDMuNzI1ODgyMjk5OTk5OTk1LC03OS4zMTU1NzE1OTk5OTk5OF0sCiAgICAgICAgICAgICAgICB7CiAgImJ1YmJsaW5nTW91c2VFdmVudHMiOiB0cnVlLAogICJjb2xvciI6ICIjZmYwMDAwIiwKICAiZGFzaEFycmF5IjogbnVsbCwKICAiZGFzaE9mZnNldCI6IG51bGwsCiAgImZpbGwiOiB0cnVlLAogICJmaWxsQ29sb3IiOiAiI2ZmMDAwMCIsCiAgImZpbGxPcGFjaXR5IjogMC43LAogICJmaWxsUnVsZSI6ICJldmVub2RkIiwKICAibGluZUNhcCI6ICJyb3VuZCIsCiAgImxpbmVKb2luIjogInJvdW5kIiwKICAib3BhY2l0eSI6IDEuMCwKICAicmFkaXVzIjogNSwKICAic3Ryb2tlIjogdHJ1ZSwKICAid2VpZ2h0IjogMwp9CiAgICAgICAgICAgICAgICApLmFkZFRvKG1hcF9mNzU1NTZhOTczNGQ0YmVmOTIzNzYyZWU1MTllYTA1OCk7CiAgICAgICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBwb3B1cF80ZDM2YjA0NjA0MjY0OTVhYmE0ZDBlZDg3ZWU3MzE4NSA9IEwucG9wdXAoe21heFdpZHRoOiAnMzAwJ30pOwoKICAgICAgICAgICAgCiAgICAgICAgICAgICAgICB2YXIgaHRtbF9jOTY0ODIwYTA1MjE0YmM0OWViZWZmMzFmY2FlYjRkOCA9ICQoJzxkaXYgaWQ9Imh0bWxfYzk2NDgyMGEwNTIxNGJjNDllYmVmZjMxZmNhZWI0ZDgiIHN0eWxlPSJ3aWR0aDogMTAwLjAlOyBoZWlnaHQ6IDEwMC4wJTsiPlZpY3RvcmlhIFZpbGxhZ2UgQ2x1c3RlciAwPC9kaXY+JylbMF07CiAgICAgICAgICAgICAgICBwb3B1cF80ZDM2YjA0NjA0MjY0OTVhYmE0ZDBlZDg3ZWU3MzE4NS5zZXRDb250ZW50KGh0bWxfYzk2NDgyMGEwNTIxNGJjNDllYmVmZjMxZmNhZWI0ZDgpOwogICAgICAgICAgICAKCiAgICAgICAgICAgIGNpcmNsZV9tYXJrZXJfYjdiMWUzYWUyNzAwNGViNTkzMWE5NzJiZGM0YTE1YWUuYmluZFBvcHVwKHBvcHVwXzRkMzZiMDQ2MDQyNjQ5NWFiYTRkMGVkODdlZTczMTg1KTsKCiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBjaXJjbGVfbWFya2VyX2QxYWQ0ZjBkNWEwNzRmYjc4NDMyYjY1ZDAzM2U5ODJlID0gTC5jaXJjbGVNYXJrZXIoCiAgICAgICAgICAgICAgICBbNDMuNzA2Mzk3MiwtNzkuMzA5OTM3XSwKICAgICAgICAgICAgICAgIHsKICAiYnViYmxpbmdNb3VzZUV2ZW50cyI6IHRydWUsCiAgImNvbG9yIjogIiNmZjAwMDAiLAogICJkYXNoQXJyYXkiOiBudWxsLAogICJkYXNoT2Zmc2V0IjogbnVsbCwKICAiZmlsbCI6IHRydWUsCiAgImZpbGxDb2xvciI6ICIjZmYwMDAwIiwKICAiZmlsbE9wYWNpdHkiOiAwLjcsCiAgImZpbGxSdWxlIjogImV2ZW5vZGQiLAogICJsaW5lQ2FwIjogInJvdW5kIiwKICAibGluZUpvaW4iOiAicm91bmQiLAogICJvcGFjaXR5IjogMS4wLAogICJyYWRpdXMiOiA1LAogICJzdHJva2UiOiB0cnVlLAogICJ3ZWlnaHQiOiAzCn0KICAgICAgICAgICAgICAgICkuYWRkVG8obWFwX2Y3NTU1NmE5NzM0ZDRiZWY5MjM3NjJlZTUxOWVhMDU4KTsKICAgICAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIHBvcHVwX2RhMzBhYzRiYjFhYjQ5Y2JhZGZiMzBiYmRlODMxNmViID0gTC5wb3B1cCh7bWF4V2lkdGg6ICczMDAnfSk7CgogICAgICAgICAgICAKICAgICAgICAgICAgICAgIHZhciBodG1sXzZkOGM3Mjk5ZGU4ODRiYzVhMzJiNWI5NDcwZDZmOGM3ID0gJCgnPGRpdiBpZD0iaHRtbF82ZDhjNzI5OWRlODg0YmM1YTMyYjViOTQ3MGQ2ZjhjNyIgc3R5bGU9IndpZHRoOiAxMDAuMCU7IGhlaWdodDogMTAwLjAlOyI+UGFya3ZpZXcgSGlsbCAvIFdvb2RiaW5lIEdhcmRlbnMgQ2x1c3RlciAwPC9kaXY+JylbMF07CiAgICAgICAgICAgICAgICBwb3B1cF9kYTMwYWM0YmIxYWI0OWNiYWRmYjMwYmJkZTgzMTZlYi5zZXRDb250ZW50KGh0bWxfNmQ4YzcyOTlkZTg4NGJjNWEzMmI1Yjk0NzBkNmY4YzcpOwogICAgICAgICAgICAKCiAgICAgICAgICAgIGNpcmNsZV9tYXJrZXJfZDFhZDRmMGQ1YTA3NGZiNzg0MzJiNjVkMDMzZTk4MmUuYmluZFBvcHVwKHBvcHVwX2RhMzBhYzRiYjFhYjQ5Y2JhZGZiMzBiYmRlODMxNmViKTsKCiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBjaXJjbGVfbWFya2VyXzE1NzVhMDNhMGY5YTQ5OGVhNWNkOTNmNWQxOTVkZmNkID0gTC5jaXJjbGVNYXJrZXIoCiAgICAgICAgICAgICAgICBbNDMuNzU2MzAzMywtNzkuNTY1OTYzMjk5OTk5OTldLAogICAgICAgICAgICAgICAgewogICJidWJibGluZ01vdXNlRXZlbnRzIjogdHJ1ZSwKICAiY29sb3IiOiAiI2ZmMDAwMCIsCiAgImRhc2hBcnJheSI6IG51bGwsCiAgImRhc2hPZmZzZXQiOiBudWxsLAogICJmaWxsIjogdHJ1ZSwKICAiZmlsbENvbG9yIjogIiNmZjAwMDAiLAogICJmaWxsT3BhY2l0eSI6IDAuNywKICAiZmlsbFJ1bGUiOiAiZXZlbm9kZCIsCiAgImxpbmVDYXAiOiAicm91bmQiLAogICJsaW5lSm9pbiI6ICJyb3VuZCIsCiAgIm9wYWNpdHkiOiAxLjAsCiAgInJhZGl1cyI6IDUsCiAgInN0cm9rZSI6IHRydWUsCiAgIndlaWdodCI6IDMKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfZjc1NTU2YTk3MzRkNGJlZjkyMzc2MmVlNTE5ZWEwNTgpOwogICAgICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgcG9wdXBfZmY2MjE3ZjU5YWRkNGY5OTk4MTM3OGQ0MmI5OTQzZjMgPSBMLnBvcHVwKHttYXhXaWR0aDogJzMwMCd9KTsKCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgdmFyIGh0bWxfZTZlM2MwOGU1NTUzNDQ5ZGI4NTcxNmQ2YjYyOGViMjggPSAkKCc8ZGl2IGlkPSJodG1sX2U2ZTNjMDhlNTU1MzQ0OWRiODU3MTZkNmI2MjhlYjI4IiBzdHlsZT0id2lkdGg6IDEwMC4wJTsgaGVpZ2h0OiAxMDAuMCU7Ij5IdW1iZXIgU3VtbWl0IENsdXN0ZXIgMDwvZGl2PicpWzBdOwogICAgICAgICAgICAgICAgcG9wdXBfZmY2MjE3ZjU5YWRkNGY5OTk4MTM3OGQ0MmI5OTQzZjMuc2V0Q29udGVudChodG1sX2U2ZTNjMDhlNTU1MzQ0OWRiODU3MTZkNmI2MjhlYjI4KTsKICAgICAgICAgICAgCgogICAgICAgICAgICBjaXJjbGVfbWFya2VyXzE1NzVhMDNhMGY5YTQ5OGVhNWNkOTNmNWQxOTVkZmNkLmJpbmRQb3B1cChwb3B1cF9mZjYyMTdmNTlhZGQ0Zjk5OTgxMzc4ZDQyYjk5NDNmMyk7CgogICAgICAgICAgICAKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgY2lyY2xlX21hcmtlcl83ZDQxZDJmNDBlZmM0ZDgwYmYxNzA5ZWE2MzNkYTJlZCA9IEwuY2lyY2xlTWFya2VyKAogICAgICAgICAgICAgICAgWzQzLjY5NjMxOSwtNzkuNTMyMjQyNDAwMDAwMDJdLAogICAgICAgICAgICAgICAgewogICJidWJibGluZ01vdXNlRXZlbnRzIjogdHJ1ZSwKICAiY29sb3IiOiAiI2ZmMDAwMCIsCiAgImRhc2hBcnJheSI6IG51bGwsCiAgImRhc2hPZmZzZXQiOiBudWxsLAogICJmaWxsIjogdHJ1ZSwKICAiZmlsbENvbG9yIjogIiNmZjAwMDAiLAogICJmaWxsT3BhY2l0eSI6IDAuNywKICAiZmlsbFJ1bGUiOiAiZXZlbm9kZCIsCiAgImxpbmVDYXAiOiAicm91bmQiLAogICJsaW5lSm9pbiI6ICJyb3VuZCIsCiAgIm9wYWNpdHkiOiAxLjAsCiAgInJhZGl1cyI6IDUsCiAgInN0cm9rZSI6IHRydWUsCiAgIndlaWdodCI6IDMKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfZjc1NTU2YTk3MzRkNGJlZjkyMzc2MmVlNTE5ZWEwNTgpOwogICAgICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgcG9wdXBfMDgwNjNjNTA3MTY1NDdlNWE2YzY3YTUxZmU1Y2VmZjMgPSBMLnBvcHVwKHttYXhXaWR0aDogJzMwMCd9KTsKCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgdmFyIGh0bWxfNmIzNTZkOTBlNDkxNDUyY2I3YjU1ODhkNzEzYWMzNjMgPSAkKCc8ZGl2IGlkPSJodG1sXzZiMzU2ZDkwZTQ5MTQ1MmNiN2I1NTg4ZDcxM2FjMzYzIiBzdHlsZT0id2lkdGg6IDEwMC4wJTsgaGVpZ2h0OiAxMDAuMCU7Ij5XZXN0bW91bnQgQ2x1c3RlciAwPC9kaXY+JylbMF07CiAgICAgICAgICAgICAgICBwb3B1cF8wODA2M2M1MDcxNjU0N2U1YTZjNjdhNTFmZTVjZWZmMy5zZXRDb250ZW50KGh0bWxfNmIzNTZkOTBlNDkxNDUyY2I3YjU1ODhkNzEzYWMzNjMpOwogICAgICAgICAgICAKCiAgICAgICAgICAgIGNpcmNsZV9tYXJrZXJfN2Q0MWQyZjQwZWZjNGQ4MGJmMTcwOWVhNjMzZGEyZWQuYmluZFBvcHVwKHBvcHVwXzA4MDYzYzUwNzE2NTQ3ZTVhNmM2N2E1MWZlNWNlZmYzKTsKCiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciBjaXJjbGVfbWFya2VyX2E2MTMxMzQxMmMwNzQzZjRiMGRhNzM4ODVhM2FmZjZiID0gTC5jaXJjbGVNYXJrZXIoCiAgICAgICAgICAgICAgICBbNDMuNjg4OTA1NCwtNzkuNTU0NzI0NDAwMDAwMDFdLAogICAgICAgICAgICAgICAgewogICJidWJibGluZ01vdXNlRXZlbnRzIjogdHJ1ZSwKICAiY29sb3IiOiAiI2ZmMDAwMCIsCiAgImRhc2hBcnJheSI6IG51bGwsCiAgImRhc2hPZmZzZXQiOiBudWxsLAogICJmaWxsIjogdHJ1ZSwKICAiZmlsbENvbG9yIjogIiNmZjAwMDAiLAogICJmaWxsT3BhY2l0eSI6IDAuNywKICAiZmlsbFJ1bGUiOiAiZXZlbm9kZCIsCiAgImxpbmVDYXAiOiAicm91bmQiLAogICJsaW5lSm9pbiI6ICJyb3VuZCIsCiAgIm9wYWNpdHkiOiAxLjAsCiAgInJhZGl1cyI6IDUsCiAgInN0cm9rZSI6IHRydWUsCiAgIndlaWdodCI6IDMKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfZjc1NTU2YTk3MzRkNGJlZjkyMzc2MmVlNTE5ZWEwNTgpOwogICAgICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgcG9wdXBfYmU0ODBjZWNmMzZiNDFlNmJkYzQxZjViYzA5NTdlZWYgPSBMLnBvcHVwKHttYXhXaWR0aDogJzMwMCd9KTsKCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgdmFyIGh0bWxfNzI3MGY1OTdjOWRiNDZhMjgyNTA4YzRjMjg4ZmQ5MWQgPSAkKCc8ZGl2IGlkPSJodG1sXzcyNzBmNTk3YzlkYjQ2YTI4MjUwOGM0YzI4OGZkOTFkIiBzdHlsZT0id2lkdGg6IDEwMC4wJTsgaGVpZ2h0OiAxMDAuMCU7Ij5LaW5nc3ZpZXcgVmlsbGFnZSAvIFN0LiBQaGlsbGlwcyAvIE1hcnRpbiBHcm92ZSBHYXJkZW5zIC8gUmljaHZpZXcgR2FyZGVucyBDbHVzdGVyIDA8L2Rpdj4nKVswXTsKICAgICAgICAgICAgICAgIHBvcHVwX2JlNDgwY2VjZjM2YjQxZTZiZGM0MWY1YmMwOTU3ZWVmLnNldENvbnRlbnQoaHRtbF83MjcwZjU5N2M5ZGI0NmEyODI1MDhjNGMyODhmZDkxZCk7CiAgICAgICAgICAgIAoKICAgICAgICAgICAgY2lyY2xlX21hcmtlcl9hNjEzMTM0MTJjMDc0M2Y0YjBkYTczODg1YTNhZmY2Yi5iaW5kUG9wdXAocG9wdXBfYmU0ODBjZWNmMzZiNDFlNmJkYzQxZjViYzA5NTdlZWYpOwoKICAgICAgICAgICAgCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIGNpcmNsZV9tYXJrZXJfYzBjNmUyODY1MGU3NDc3NjkwZWUzZWZkYWYwNThmM2IgPSBMLmNpcmNsZU1hcmtlcigKICAgICAgICAgICAgICAgIFs0My42MDI0MTM3MDAwMDAwMSwtNzkuNTQzNDg0MDk5OTk5OTldLAogICAgICAgICAgICAgICAgewogICJidWJibGluZ01vdXNlRXZlbnRzIjogdHJ1ZSwKICAiY29sb3IiOiAiI2ZmMDAwMCIsCiAgImRhc2hBcnJheSI6IG51bGwsCiAgImRhc2hPZmZzZXQiOiBudWxsLAogICJmaWxsIjogdHJ1ZSwKICAiZmlsbENvbG9yIjogIiNmZjAwMDAiLAogICJmaWxsT3BhY2l0eSI6IDAuNywKICAiZmlsbFJ1bGUiOiAiZXZlbm9kZCIsCiAgImxpbmVDYXAiOiAicm91bmQiLAogICJsaW5lSm9pbiI6ICJyb3VuZCIsCiAgIm9wYWNpdHkiOiAxLjAsCiAgInJhZGl1cyI6IDUsCiAgInN0cm9rZSI6IHRydWUsCiAgIndlaWdodCI6IDMKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfZjc1NTU2YTk3MzRkNGJlZjkyMzc2MmVlNTE5ZWEwNTgpOwogICAgICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgcG9wdXBfZTMyMzU0YTgwNzU3NDAyMjk1MmFjYjY0MmM4YTYyMGEgPSBMLnBvcHVwKHttYXhXaWR0aDogJzMwMCd9KTsKCiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgdmFyIGh0bWxfNGFiYmY3ZmZkNjIwNDlmZmI0MWQwMzM3NDAwMmJjMWIgPSAkKCc8ZGl2IGlkPSJodG1sXzRhYmJmN2ZmZDYyMDQ5ZmZiNDFkMDMzNzQwMDJiYzFiIiBzdHlsZT0id2lkdGg6IDEwMC4wJTsgaGVpZ2h0OiAxMDAuMCU7Ij5BbGRlcndvb2QgLyBMb25nIEJyYW5jaCBDbHVzdGVyIDA8L2Rpdj4nKVswXTsKICAgICAgICAgICAgICAgIHBvcHVwX2UzMjM1NGE4MDc1NzQwMjI5NTJhY2I2NDJjOGE2MjBhLnNldENvbnRlbnQoaHRtbF80YWJiZjdmZmQ2MjA0OWZmYjQxZDAzMzc0MDAyYmMxYik7CiAgICAgICAgICAgIAoKICAgICAgICAgICAgY2lyY2xlX21hcmtlcl9jMGM2ZTI4NjUwZTc0Nzc2OTBlZTNlZmRhZjA1OGYzYi5iaW5kUG9wdXAocG9wdXBfZTMyMzU0YTgwNzU3NDAyMjk1MmFjYjY0MmM4YTYyMGEpOwoKICAgICAgICAgICAgCiAgICAgICAgCjwvc2NyaXB0Pg== onload=\"this.contentDocument.open();this.contentDocument.write(atob(this.getAttribute('data-html')));this.contentDocument.close();\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
],
"text/plain": [
"<folium.folium.Map at 0x7fee676e1e48>"
]
},
"execution_count": 152,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create map\n",
"map_cluster_NY = folium.Map(location=[latitude, longitude], zoom_start=11)\n",
"\n",
"# set color scheme for the clusters\n",
"x = np.arange(kclusters)\n",
"ys = [i + x + (i*x)**2 for i in range(kclusters)]\n",
"colors_array = cm.rainbow(np.linspace(0, 1, len(ys)))\n",
"rainbow = [colors.rgb2hex(i) for i in colors_array]\n",
"\n",
"# add markers to the map\n",
"markers_colors = []\n",
"for lat, lon, poi, cluster in zip(toronto_merged['Latitude'], toronto_merged['Longitude'], toronto_merged['Neighborhood'], toronto_merged['Cluster Labels']):\n",
" if cluster == NY_cluster: \n",
" label = folium.Popup(str(poi) + ' Cluster ' + str(cluster), parse_html=True)\n",
" folium.CircleMarker(\n",
" [lat, lon],\n",
" radius=5,\n",
" popup=label,\n",
" color=rainbow[cluster-1],\n",
" fill=True,\n",
" fill_color=rainbow[cluster-1],\n",
" fill_opacity=0.7).add_to(map_cluster_NY)\n",
" \n",
"map_cluster_NY"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"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.6.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment