Skip to content

Instantly share code, notes, and snippets.

@rquintel
Created July 14, 2019 20:28
Show Gist options
  • Save rquintel/1f1a6d21c261d8d847f03ec882935dd5 to your computer and use it in GitHub Desktop.
Save rquintel/1f1a6d21c261d8d847f03ec882935dd5 to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"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>Postcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighbourhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M1A</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M2A</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</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>Harbourfront</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>M7A</td>\n",
" <td>Queen's Park</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>M8A</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>M9A</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Malvern</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>M2B</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>M3B</td>\n",
" <td>North York</td>\n",
" <td>Don Mills North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>M4B</td>\n",
" <td>East York</td>\n",
" <td>Woodbine Gardens</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>M4B</td>\n",
" <td>East York</td>\n",
" <td>Parkview Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>M5B</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Ryerson</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>M5B</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Garden District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>M6B</td>\n",
" <td>North York</td>\n",
" <td>Glencairn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>M7B</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>M8B</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Cloverdale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Martin Grove</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Princess Gardens</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>West Deane Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Highland Creek</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Rouge Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Port Union</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>258</th>\n",
" <td>M9X</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>259</th>\n",
" <td>M1Y</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>260</th>\n",
" <td>M2Y</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>261</th>\n",
" <td>M3Y</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>262</th>\n",
" <td>M4Y</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Church and Wellesley</td>\n",
" </tr>\n",
" <tr>\n",
" <th>263</th>\n",
" <td>M5Y</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>264</th>\n",
" <td>M6Y</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>265</th>\n",
" <td>M7Y</td>\n",
" <td>East Toronto</td>\n",
" <td>Business Reply Mail Processing Centre 969 Eastern</td>\n",
" </tr>\n",
" <tr>\n",
" <th>266</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Humber Bay</td>\n",
" </tr>\n",
" <tr>\n",
" <th>267</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>King's Mill Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>269</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico NE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>270</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Old Mill South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>271</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>The Queensway East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>272</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Royal York South East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>273</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Sunnylea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>274</th>\n",
" <td>M9Y</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>275</th>\n",
" <td>M1Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>276</th>\n",
" <td>M2Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>277</th>\n",
" <td>M3Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>278</th>\n",
" <td>M4Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>279</th>\n",
" <td>M5Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>280</th>\n",
" <td>M6Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>281</th>\n",
" <td>M7Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" <tr>\n",
" <th>282</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>283</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico NW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>284</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>The Queensway West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>285</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Royal York South West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>286</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>South of Bloor</td>\n",
" </tr>\n",
" <tr>\n",
" <th>287</th>\n",
" <td>M9Z</td>\n",
" <td>Not assigned</td>\n",
" <td>Not assigned</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>288 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Postcode Borough \\\n",
"0 M1A Not assigned \n",
"1 M2A Not assigned \n",
"2 M3A North York \n",
"3 M4A North York \n",
"4 M5A Downtown Toronto \n",
"5 M5A Downtown Toronto \n",
"6 M6A North York \n",
"7 M6A North York \n",
"8 M7A Queen's Park \n",
"9 M8A Not assigned \n",
"10 M9A Etobicoke \n",
"11 M1B Scarborough \n",
"12 M1B Scarborough \n",
"13 M2B Not assigned \n",
"14 M3B North York \n",
"15 M4B East York \n",
"16 M4B East York \n",
"17 M5B Downtown Toronto \n",
"18 M5B Downtown Toronto \n",
"19 M6B North York \n",
"20 M7B Not assigned \n",
"21 M8B Not assigned \n",
"22 M9B Etobicoke \n",
"23 M9B Etobicoke \n",
"24 M9B Etobicoke \n",
"25 M9B Etobicoke \n",
"26 M9B Etobicoke \n",
"27 M1C Scarborough \n",
"28 M1C Scarborough \n",
"29 M1C Scarborough \n",
".. ... ... \n",
"258 M9X Not assigned \n",
"259 M1Y Not assigned \n",
"260 M2Y Not assigned \n",
"261 M3Y Not assigned \n",
"262 M4Y Downtown Toronto \n",
"263 M5Y Not assigned \n",
"264 M6Y Not assigned \n",
"265 M7Y East Toronto \n",
"266 M8Y Etobicoke \n",
"267 M8Y Etobicoke \n",
"268 M8Y Etobicoke \n",
"269 M8Y Etobicoke \n",
"270 M8Y Etobicoke \n",
"271 M8Y Etobicoke \n",
"272 M8Y Etobicoke \n",
"273 M8Y Etobicoke \n",
"274 M9Y Not assigned \n",
"275 M1Z Not assigned \n",
"276 M2Z Not assigned \n",
"277 M3Z Not assigned \n",
"278 M4Z Not assigned \n",
"279 M5Z Not assigned \n",
"280 M6Z Not assigned \n",
"281 M7Z Not assigned \n",
"282 M8Z Etobicoke \n",
"283 M8Z Etobicoke \n",
"284 M8Z Etobicoke \n",
"285 M8Z Etobicoke \n",
"286 M8Z Etobicoke \n",
"287 M9Z Not assigned \n",
"\n",
" Neighbourhood \n",
"0 Not assigned \n",
"1 Not assigned \n",
"2 Parkwoods \n",
"3 Victoria Village \n",
"4 Harbourfront \n",
"5 Regent Park \n",
"6 Lawrence Heights \n",
"7 Lawrence Manor \n",
"8 Not assigned \n",
"9 Not assigned \n",
"10 Islington Avenue \n",
"11 Rouge \n",
"12 Malvern \n",
"13 Not assigned \n",
"14 Don Mills North \n",
"15 Woodbine Gardens \n",
"16 Parkview Hill \n",
"17 Ryerson \n",
"18 Garden District \n",
"19 Glencairn \n",
"20 Not assigned \n",
"21 Not assigned \n",
"22 Cloverdale \n",
"23 Islington \n",
"24 Martin Grove \n",
"25 Princess Gardens \n",
"26 West Deane Park \n",
"27 Highland Creek \n",
"28 Rouge Hill \n",
"29 Port Union \n",
".. ... \n",
"258 Not assigned \n",
"259 Not assigned \n",
"260 Not assigned \n",
"261 Not assigned \n",
"262 Church and Wellesley \n",
"263 Not assigned \n",
"264 Not assigned \n",
"265 Business Reply Mail Processing Centre 969 Eastern \n",
"266 Humber Bay \n",
"267 King's Mill Park \n",
"268 Kingsway Park South East \n",
"269 Mimico NE \n",
"270 Old Mill South \n",
"271 The Queensway East \n",
"272 Royal York South East \n",
"273 Sunnylea \n",
"274 Not assigned \n",
"275 Not assigned \n",
"276 Not assigned \n",
"277 Not assigned \n",
"278 Not assigned \n",
"279 Not assigned \n",
"280 Not assigned \n",
"281 Not assigned \n",
"282 Kingsway Park South West \n",
"283 Mimico NW \n",
"284 The Queensway West \n",
"285 Royal York South West \n",
"286 South of Bloor \n",
"287 Not assigned \n",
"\n",
"[288 rows x 3 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"# Import data\n",
"link = \"https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M\"\n",
"html_table = pd.read_html(link,header=0)\n",
"postal_codes = pd.DataFrame(html_table[0])\n",
"postal_codes"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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>Postcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighbourhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\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>Harbourfront</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>M5A</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Regent Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>M6A</td>\n",
" <td>North York</td>\n",
" <td>Lawrence Manor</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>M7A</td>\n",
" <td>Queen's Park</td>\n",
" <td>Queen's Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>M9A</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Malvern</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>M3B</td>\n",
" <td>North York</td>\n",
" <td>Don Mills North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>M4B</td>\n",
" <td>East York</td>\n",
" <td>Woodbine Gardens</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>M4B</td>\n",
" <td>East York</td>\n",
" <td>Parkview Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>M5B</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Ryerson</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>M5B</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Garden District</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>M6B</td>\n",
" <td>North York</td>\n",
" <td>Glencairn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Cloverdale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Martin Grove</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Princess Gardens</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>West Deane Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Highland Creek</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Rouge Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Port Union</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>M3C</td>\n",
" <td>North York</td>\n",
" <td>Flemingdon Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>M3C</td>\n",
" <td>North York</td>\n",
" <td>Don Mills South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>M4C</td>\n",
" <td>East York</td>\n",
" <td>Woodbine Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>M5C</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>St. James Town</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>M6C</td>\n",
" <td>York</td>\n",
" <td>Humewood-Cedarvale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>M9C</td>\n",
" <td>Etobicoke</td>\n",
" <td>Bloordale Gardens</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>235</th>\n",
" <td>M9V</td>\n",
" <td>Etobicoke</td>\n",
" <td>Thistletown</td>\n",
" </tr>\n",
" <tr>\n",
" <th>236</th>\n",
" <td>M1W</td>\n",
" <td>Scarborough</td>\n",
" <td>L'Amoreaux West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>239</th>\n",
" <td>M4W</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Rosedale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>240</th>\n",
" <td>M5W</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Stn A PO Boxes 25 The Esplanade</td>\n",
" </tr>\n",
" <tr>\n",
" <th>243</th>\n",
" <td>M8W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood</td>\n",
" </tr>\n",
" <tr>\n",
" <th>244</th>\n",
" <td>M8W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Long Branch</td>\n",
" </tr>\n",
" <tr>\n",
" <th>245</th>\n",
" <td>M9W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" </tr>\n",
" <tr>\n",
" <th>246</th>\n",
" <td>M1X</td>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>249</th>\n",
" <td>M4X</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Cabbagetown</td>\n",
" </tr>\n",
" <tr>\n",
" <th>250</th>\n",
" <td>M4X</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>St. James Town</td>\n",
" </tr>\n",
" <tr>\n",
" <th>251</th>\n",
" <td>M5X</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>First Canadian Place</td>\n",
" </tr>\n",
" <tr>\n",
" <th>252</th>\n",
" <td>M5X</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Underground city</td>\n",
" </tr>\n",
" <tr>\n",
" <th>255</th>\n",
" <td>M8X</td>\n",
" <td>Etobicoke</td>\n",
" <td>The Kingsway</td>\n",
" </tr>\n",
" <tr>\n",
" <th>256</th>\n",
" <td>M8X</td>\n",
" <td>Etobicoke</td>\n",
" <td>Montgomery Road</td>\n",
" </tr>\n",
" <tr>\n",
" <th>257</th>\n",
" <td>M8X</td>\n",
" <td>Etobicoke</td>\n",
" <td>Old Mill North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>262</th>\n",
" <td>M4Y</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Church and Wellesley</td>\n",
" </tr>\n",
" <tr>\n",
" <th>265</th>\n",
" <td>M7Y</td>\n",
" <td>East Toronto</td>\n",
" <td>Business Reply Mail Processing Centre 969 Eastern</td>\n",
" </tr>\n",
" <tr>\n",
" <th>266</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Humber Bay</td>\n",
" </tr>\n",
" <tr>\n",
" <th>267</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>King's Mill Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>269</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico NE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>270</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Old Mill South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>271</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>The Queensway East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>272</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Royal York South East</td>\n",
" </tr>\n",
" <tr>\n",
" <th>273</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Sunnylea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>282</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>283</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico NW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>284</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>The Queensway West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>285</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Royal York South West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>286</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>South of Bloor</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>211 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Postcode Borough \\\n",
"2 M3A North York \n",
"3 M4A North York \n",
"4 M5A Downtown Toronto \n",
"5 M5A Downtown Toronto \n",
"6 M6A North York \n",
"7 M6A North York \n",
"8 M7A Queen's Park \n",
"10 M9A Etobicoke \n",
"11 M1B Scarborough \n",
"12 M1B Scarborough \n",
"14 M3B North York \n",
"15 M4B East York \n",
"16 M4B East York \n",
"17 M5B Downtown Toronto \n",
"18 M5B Downtown Toronto \n",
"19 M6B North York \n",
"22 M9B Etobicoke \n",
"23 M9B Etobicoke \n",
"24 M9B Etobicoke \n",
"25 M9B Etobicoke \n",
"26 M9B Etobicoke \n",
"27 M1C Scarborough \n",
"28 M1C Scarborough \n",
"29 M1C Scarborough \n",
"31 M3C North York \n",
"32 M3C North York \n",
"33 M4C East York \n",
"34 M5C Downtown Toronto \n",
"35 M6C York \n",
"38 M9C Etobicoke \n",
".. ... ... \n",
"235 M9V Etobicoke \n",
"236 M1W Scarborough \n",
"239 M4W Downtown Toronto \n",
"240 M5W Downtown Toronto \n",
"243 M8W Etobicoke \n",
"244 M8W Etobicoke \n",
"245 M9W Etobicoke \n",
"246 M1X Scarborough \n",
"249 M4X Downtown Toronto \n",
"250 M4X Downtown Toronto \n",
"251 M5X Downtown Toronto \n",
"252 M5X Downtown Toronto \n",
"255 M8X Etobicoke \n",
"256 M8X Etobicoke \n",
"257 M8X Etobicoke \n",
"262 M4Y Downtown Toronto \n",
"265 M7Y East Toronto \n",
"266 M8Y Etobicoke \n",
"267 M8Y Etobicoke \n",
"268 M8Y Etobicoke \n",
"269 M8Y Etobicoke \n",
"270 M8Y Etobicoke \n",
"271 M8Y Etobicoke \n",
"272 M8Y Etobicoke \n",
"273 M8Y Etobicoke \n",
"282 M8Z Etobicoke \n",
"283 M8Z Etobicoke \n",
"284 M8Z Etobicoke \n",
"285 M8Z Etobicoke \n",
"286 M8Z Etobicoke \n",
"\n",
" Neighbourhood \n",
"2 Parkwoods \n",
"3 Victoria Village \n",
"4 Harbourfront \n",
"5 Regent Park \n",
"6 Lawrence Heights \n",
"7 Lawrence Manor \n",
"8 Queen's Park \n",
"10 Islington Avenue \n",
"11 Rouge \n",
"12 Malvern \n",
"14 Don Mills North \n",
"15 Woodbine Gardens \n",
"16 Parkview Hill \n",
"17 Ryerson \n",
"18 Garden District \n",
"19 Glencairn \n",
"22 Cloverdale \n",
"23 Islington \n",
"24 Martin Grove \n",
"25 Princess Gardens \n",
"26 West Deane Park \n",
"27 Highland Creek \n",
"28 Rouge Hill \n",
"29 Port Union \n",
"31 Flemingdon Park \n",
"32 Don Mills South \n",
"33 Woodbine Heights \n",
"34 St. James Town \n",
"35 Humewood-Cedarvale \n",
"38 Bloordale Gardens \n",
".. ... \n",
"235 Thistletown \n",
"236 L'Amoreaux West \n",
"239 Rosedale \n",
"240 Stn A PO Boxes 25 The Esplanade \n",
"243 Alderwood \n",
"244 Long Branch \n",
"245 Northwest \n",
"246 Upper Rouge \n",
"249 Cabbagetown \n",
"250 St. James Town \n",
"251 First Canadian Place \n",
"252 Underground city \n",
"255 The Kingsway \n",
"256 Montgomery Road \n",
"257 Old Mill North \n",
"262 Church and Wellesley \n",
"265 Business Reply Mail Processing Centre 969 Eastern \n",
"266 Humber Bay \n",
"267 King's Mill Park \n",
"268 Kingsway Park South East \n",
"269 Mimico NE \n",
"270 Old Mill South \n",
"271 The Queensway East \n",
"272 Royal York South East \n",
"273 Sunnylea \n",
"282 Kingsway Park South West \n",
"283 Mimico NW \n",
"284 The Queensway West \n",
"285 Royal York South West \n",
"286 South of Bloor \n",
"\n",
"[211 rows x 3 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Cleaning\n",
"postal_codes.replace(\"Not assigned\", np.nan, inplace = True)\n",
"postal_codes.dropna(subset=[\"Borough\"], axis=0, inplace = True)\n",
"postal_codes.Neighbourhood.fillna(postal_codes.Borough, inplace = True)\n",
"postal_codes"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>Postcode</th>\n",
" <th>Borough</th>\n",
" <th>Neighbourhood</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Rouge, Malvern</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>M1C</td>\n",
" <td>Scarborough</td>\n",
" <td>Highland Creek, Rouge Hill, Port Union</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>M1E</td>\n",
" <td>Scarborough</td>\n",
" <td>Guildwood, Morningside, West Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>M1G</td>\n",
" <td>Scarborough</td>\n",
" <td>Woburn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>M1H</td>\n",
" <td>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>M1J</td>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>M1K</td>\n",
" <td>Scarborough</td>\n",
" <td>East Birchmount Park, Ionview, Kennedy Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>M1L</td>\n",
" <td>Scarborough</td>\n",
" <td>Clairlea, Golden Mile, Oakridge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>M1M</td>\n",
" <td>Scarborough</td>\n",
" <td>Cliffcrest, Cliffside, Scarborough Village West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>M1N</td>\n",
" <td>Scarborough</td>\n",
" <td>Birch Cliff, Cliffside West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>M1P</td>\n",
" <td>Scarborough</td>\n",
" <td>Dorset Park, Scarborough Town Centre, Wexford ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>M1R</td>\n",
" <td>Scarborough</td>\n",
" <td>Maryvale, Wexford</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>M1S</td>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>M1T</td>\n",
" <td>Scarborough</td>\n",
" <td>Clarks Corners, Sullivan, Tam O'Shanter</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>M1V</td>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt North, L'Amoreaux East, Milliken, St...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>M1W</td>\n",
" <td>Scarborough</td>\n",
" <td>L'Amoreaux West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>M1X</td>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>M2H</td>\n",
" <td>North York</td>\n",
" <td>Hillcrest Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>M2J</td>\n",
" <td>North York</td>\n",
" <td>Fairview, Henry Farm, Oriole</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>M2K</td>\n",
" <td>North York</td>\n",
" <td>Bayview Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>M2L</td>\n",
" <td>North York</td>\n",
" <td>Silver Hills, York Mills</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>M2M</td>\n",
" <td>North York</td>\n",
" <td>Newtonbrook, Willowdale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>M2N</td>\n",
" <td>North York</td>\n",
" <td>Willowdale South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>M2P</td>\n",
" <td>North York</td>\n",
" <td>York Mills West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>M2R</td>\n",
" <td>North York</td>\n",
" <td>Willowdale West</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>M3A</td>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>M3B</td>\n",
" <td>North York</td>\n",
" <td>Don Mills North</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>M3C</td>\n",
" <td>North York</td>\n",
" <td>Flemingdon Park, Don Mills South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>M3H</td>\n",
" <td>North York</td>\n",
" <td>Bathurst Manor, Downsview North, Wilson Heights</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>M3J</td>\n",
" <td>North York</td>\n",
" <td>Northwood Park, York University</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>73</th>\n",
" <td>M6C</td>\n",
" <td>York</td>\n",
" <td>Humewood-Cedarvale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>M6E</td>\n",
" <td>York</td>\n",
" <td>Caledonia-Fairbanks</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75</th>\n",
" <td>M6G</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Christie</td>\n",
" </tr>\n",
" <tr>\n",
" <th>76</th>\n",
" <td>M6H</td>\n",
" <td>West Toronto</td>\n",
" <td>Dovercourt Village, Dufferin</td>\n",
" </tr>\n",
" <tr>\n",
" <th>77</th>\n",
" <td>M6J</td>\n",
" <td>West Toronto</td>\n",
" <td>Little Portugal, Trinity</td>\n",
" </tr>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>M6K</td>\n",
" <td>West Toronto</td>\n",
" <td>Brockton, Exhibition Place, Parkdale Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>79</th>\n",
" <td>M6L</td>\n",
" <td>North York</td>\n",
" <td>Downsview, North Park, Upwood Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>M6M</td>\n",
" <td>York</td>\n",
" <td>Del Ray, Keelesdale, Mount Dennis, Silverthorn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>81</th>\n",
" <td>M6N</td>\n",
" <td>York</td>\n",
" <td>The Junction North, Runnymede</td>\n",
" </tr>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>M6P</td>\n",
" <td>West Toronto</td>\n",
" <td>High Park, The Junction South</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>M6R</td>\n",
" <td>West Toronto</td>\n",
" <td>Parkdale, Roncesvalles</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>M6S</td>\n",
" <td>West Toronto</td>\n",
" <td>Runnymede, Swansea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>M7A</td>\n",
" <td>Queen's Park</td>\n",
" <td>Queen's Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>86</th>\n",
" <td>M7R</td>\n",
" <td>Mississauga</td>\n",
" <td>Canada Post Gateway Processing Centre</td>\n",
" </tr>\n",
" <tr>\n",
" <th>87</th>\n",
" <td>M7Y</td>\n",
" <td>East Toronto</td>\n",
" <td>Business Reply Mail Processing Centre 969 Eastern</td>\n",
" </tr>\n",
" <tr>\n",
" <th>88</th>\n",
" <td>M8V</td>\n",
" <td>Etobicoke</td>\n",
" <td>Humber Bay Shores, Mimico South, New Toronto</td>\n",
" </tr>\n",
" <tr>\n",
" <th>89</th>\n",
" <td>M8W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood, Long Branch</td>\n",
" </tr>\n",
" <tr>\n",
" <th>90</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>91</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Humber Bay, King's Mill Park, Kingsway Park So...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West, Mimico NW, The Queen...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>93</th>\n",
" <td>M9A</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" </tr>\n",
" <tr>\n",
" <th>94</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Cloverdale, Islington, Martin Grove, Princess ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>M9C</td>\n",
" <td>Etobicoke</td>\n",
" <td>Bloordale Gardens, Eringate, Markland Wood, Ol...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>M9L</td>\n",
" <td>North York</td>\n",
" <td>Humber Summit</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>M9M</td>\n",
" <td>North York</td>\n",
" <td>Emery, Humberlea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>M9N</td>\n",
" <td>York</td>\n",
" <td>Weston</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
" <td>M9P</td>\n",
" <td>Etobicoke</td>\n",
" <td>Westmount</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>M9R</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsview Village, Martin Grove Gardens, Richv...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>M9V</td>\n",
" <td>Etobicoke</td>\n",
" <td>Albion Gardens, Beaumond Heights, Humbergate, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>M9W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>103 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Postcode Borough \\\n",
"0 M1B Scarborough \n",
"1 M1C Scarborough \n",
"2 M1E Scarborough \n",
"3 M1G Scarborough \n",
"4 M1H Scarborough \n",
"5 M1J Scarborough \n",
"6 M1K Scarborough \n",
"7 M1L Scarborough \n",
"8 M1M Scarborough \n",
"9 M1N Scarborough \n",
"10 M1P Scarborough \n",
"11 M1R Scarborough \n",
"12 M1S Scarborough \n",
"13 M1T Scarborough \n",
"14 M1V Scarborough \n",
"15 M1W Scarborough \n",
"16 M1X Scarborough \n",
"17 M2H North York \n",
"18 M2J North York \n",
"19 M2K North York \n",
"20 M2L North York \n",
"21 M2M North York \n",
"22 M2N North York \n",
"23 M2P North York \n",
"24 M2R North York \n",
"25 M3A North York \n",
"26 M3B North York \n",
"27 M3C North York \n",
"28 M3H North York \n",
"29 M3J North York \n",
".. ... ... \n",
"73 M6C York \n",
"74 M6E York \n",
"75 M6G Downtown Toronto \n",
"76 M6H West Toronto \n",
"77 M6J West Toronto \n",
"78 M6K West Toronto \n",
"79 M6L North York \n",
"80 M6M York \n",
"81 M6N York \n",
"82 M6P West Toronto \n",
"83 M6R West Toronto \n",
"84 M6S West Toronto \n",
"85 M7A Queen's Park \n",
"86 M7R Mississauga \n",
"87 M7Y East Toronto \n",
"88 M8V Etobicoke \n",
"89 M8W Etobicoke \n",
"90 M8X Etobicoke \n",
"91 M8Y Etobicoke \n",
"92 M8Z Etobicoke \n",
"93 M9A Etobicoke \n",
"94 M9B Etobicoke \n",
"95 M9C Etobicoke \n",
"96 M9L North York \n",
"97 M9M North York \n",
"98 M9N York \n",
"99 M9P Etobicoke \n",
"100 M9R Etobicoke \n",
"101 M9V Etobicoke \n",
"102 M9W Etobicoke \n",
"\n",
" Neighbourhood \n",
"0 Rouge, Malvern \n",
"1 Highland Creek, Rouge Hill, Port Union \n",
"2 Guildwood, Morningside, West Hill \n",
"3 Woburn \n",
"4 Cedarbrae \n",
"5 Scarborough Village \n",
"6 East Birchmount Park, Ionview, Kennedy Park \n",
"7 Clairlea, Golden Mile, Oakridge \n",
"8 Cliffcrest, Cliffside, Scarborough Village West \n",
"9 Birch Cliff, Cliffside West \n",
"10 Dorset Park, Scarborough Town Centre, Wexford ... \n",
"11 Maryvale, Wexford \n",
"12 Agincourt \n",
"13 Clarks Corners, Sullivan, Tam O'Shanter \n",
"14 Agincourt North, L'Amoreaux East, Milliken, St... \n",
"15 L'Amoreaux West \n",
"16 Upper Rouge \n",
"17 Hillcrest Village \n",
"18 Fairview, Henry Farm, Oriole \n",
"19 Bayview Village \n",
"20 Silver Hills, York Mills \n",
"21 Newtonbrook, Willowdale \n",
"22 Willowdale South \n",
"23 York Mills West \n",
"24 Willowdale West \n",
"25 Parkwoods \n",
"26 Don Mills North \n",
"27 Flemingdon Park, Don Mills South \n",
"28 Bathurst Manor, Downsview North, Wilson Heights \n",
"29 Northwood Park, York University \n",
".. ... \n",
"73 Humewood-Cedarvale \n",
"74 Caledonia-Fairbanks \n",
"75 Christie \n",
"76 Dovercourt Village, Dufferin \n",
"77 Little Portugal, Trinity \n",
"78 Brockton, Exhibition Place, Parkdale Village \n",
"79 Downsview, North Park, Upwood Park \n",
"80 Del Ray, Keelesdale, Mount Dennis, Silverthorn \n",
"81 The Junction North, Runnymede \n",
"82 High Park, The Junction South \n",
"83 Parkdale, Roncesvalles \n",
"84 Runnymede, Swansea \n",
"85 Queen's Park \n",
"86 Canada Post Gateway Processing Centre \n",
"87 Business Reply Mail Processing Centre 969 Eastern \n",
"88 Humber Bay Shores, Mimico South, New Toronto \n",
"89 Alderwood, Long Branch \n",
"90 The Kingsway, Montgomery Road, Old Mill North \n",
"91 Humber Bay, King's Mill Park, Kingsway Park So... \n",
"92 Kingsway Park South West, Mimico NW, The Queen... \n",
"93 Islington Avenue \n",
"94 Cloverdale, Islington, Martin Grove, Princess ... \n",
"95 Bloordale Gardens, Eringate, Markland Wood, Ol... \n",
"96 Humber Summit \n",
"97 Emery, Humberlea \n",
"98 Weston \n",
"99 Westmount \n",
"100 Kingsview Village, Martin Grove Gardens, Richv... \n",
"101 Albion Gardens, Beaumond Heights, Humbergate, ... \n",
"102 Northwest \n",
"\n",
"[103 rows x 3 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Grouping\n",
"postal_codes = postal_codes.groupby(['Postcode','Borough'])['Neighbourhood'].apply(lambda x: ', '.join(x)).reset_index()\n",
"postal_codes"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(103, 3)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"postal_codes.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment