Skip to content

Instantly share code, notes, and snippets.

@alfredo-g-zapiola
Created March 19, 2019 17:06
Show Gist options
  • Save alfredo-g-zapiola/8cfe569efc2ddf90fc2313eed08ed478 to your computer and use it in GitHub Desktop.
Save alfredo-g-zapiola/8cfe569efc2ddf90fc2313eed08ed478 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": "markdown",
"metadata": {},
"source": [
"Neighbourhoods - Toronto\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Scrape https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M\n",
"2. Transform data to dataframe:\n",
" i. Columns: PostalCOde, Borough, Neighborhood.\n",
" ii. Not assigned buroughs: drop row.\n",
" iii. For PostalCode, append all neighbourhoods (like a group concat)\n",
" iv. If there is borough but no neighbourhood, neighborhood = borough\n",
" v. Explain steps\n",
" vi. print df.shape\n",
"3. Submit link to Github\n",
"4. Links: http://beautiful-soup-4.readthedocs.io/en/latest/\n",
" https://www.youtube.com/watch?v=ng2o98k983k"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello world\n"
]
}
],
"source": [
"print('hello world')"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"#imports\n",
"import pandas as pd\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 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",
"259 M9X Not assigned \n",
"260 M1Y Not assigned \n",
"261 M2Y Not assigned \n",
"262 M3Y Not assigned \n",
"263 M4Y Downtown Toronto \n",
"264 M5Y Not assigned \n",
"265 M6Y Not assigned \n",
"266 M7Y East Toronto \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 M8Y Etobicoke \n",
"275 M9Y Not assigned \n",
"276 M1Z Not assigned \n",
"277 M2Z Not assigned \n",
"278 M3Z Not assigned \n",
"279 M4Z Not assigned \n",
"280 M5Z Not assigned \n",
"281 M6Z Not assigned \n",
"282 M7Z Not assigned \n",
"283 M8Z Etobicoke \n",
"284 M8Z Etobicoke \n",
"285 M8Z Etobicoke \n",
"286 M8Z Etobicoke \n",
"287 M8Z Etobicoke \n",
"288 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",
"259 Not assigned \n",
"260 Not assigned \n",
"261 Not assigned \n",
"262 Not assigned \n",
"263 Church and Wellesley \n",
"264 Not assigned \n",
"265 Not assigned \n",
"266 Business Reply Mail Processing Centre 969 Eastern \n",
"267 Humber Bay \n",
"268 King's Mill Park \n",
"269 Kingsway Park South East \n",
"270 Mimico NE \n",
"271 Old Mill South \n",
"272 The Queensway East \n",
"273 Royal York South East \n",
"274 Sunnylea \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 Not assigned \n",
"283 Kingsway Park South West \n",
"284 Mimico NW \n",
"285 The Queensway West \n",
"286 Royal York South West \n",
"287 South of Bloor \n",
"288 Not assigned \n",
"\n",
"[289 rows x 3 columns], Unnamed: 0 \\\n",
"0 NL NS PE NB QC ON MB SK AB BC NU/NT YT A B C E... \n",
"1 NL \n",
"2 A \n",
"\n",
" Canadian postal codes \\\n",
"0 NL NS PE NB QC ON MB SK AB BC NU/NT YT A B C E... \n",
"1 NS \n",
"2 B \n",
"\n",
" Unnamed: 2 Unnamed: 3 Unnamed: 4 \\\n",
"0 NL NS PE NB QC ON MB SK AB BC NU/NT YT A B C E... \n",
"1 PE NB QC \n",
"2 C E G \n",
"\n",
" Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Unnamed: 9 Unnamed: 10 \\\n",
"0 \n",
"1 QC QC ON ON ON ON \n",
"2 H J K L M N \n",
"\n",
" Unnamed: 11 Unnamed: 12 Unnamed: 13 Unnamed: 14 Unnamed: 15 Unnamed: 16 \\\n",
"0 \n",
"1 ON MB SK AB BC NU/NT \n",
"2 P R S T V X \n",
"\n",
" Unnamed: 17 \n",
"0 \n",
"1 YT \n",
"2 Y , NL NS PE NB QC QC.1 QC.2 ON ON.1 ON.2 ON.3 ON.4 MB SK AB BC NU/NT YT\n",
"0 A B C E G H J K L M N P R S T V X Y]\n"
]
}
],
"source": [
"url='https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M'\n",
"\n",
"fhand = pd.read_html(url, header=0,keep_default_na=False) #returns a list of dataframes\n",
"print(fhand)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"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>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",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" PostalCode Borough Neighbourhood\n",
"0 M1A Not assigned Not assigned\n",
"1 M2A Not assigned Not assigned\n",
"2 M3A North York Parkwoods\n",
"3 M4A North York Victoria Village\n",
"4 M5A Downtown Toronto Harbourfront\n",
"5 M5A Downtown Toronto Regent Park\n",
"6 M6A North York Lawrence Heights\n",
"7 M6A North York Lawrence Manor\n",
"8 M7A Queen's Park Not assigned\n",
"9 M8A Not assigned Not assigned\n",
"10 M9A Etobicoke Islington Avenue\n",
"11 M1B Scarborough Rouge\n",
"12 M1B Scarborough Malvern\n",
"13 M2B Not assigned Not assigned\n",
"14 M3B North York Don Mills North\n",
"15 M4B East York Woodbine Gardens\n",
"16 M4B East York Parkview Hill\n",
"17 M5B Downtown Toronto Ryerson\n",
"18 M5B Downtown Toronto Garden District\n",
"19 M6B North York Glencairn"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = fhand[0]\n",
"df.head(20)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Postcode', 'Borough', 'Neighbourhood'], dtype='object')"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['PostalCode', 'Borough', 'Neighbourhood'], dtype='object')"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns = ['PostalCode', 'Borough', 'Neighbourhood']\n",
"df.columns"
]
},
{
"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>PostalCode</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",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" PostalCode Borough Neighbourhood\n",
"2 M3A North York Parkwoods\n",
"3 M4A North York Victoria Village\n",
"4 M5A Downtown Toronto Harbourfront\n",
"5 M5A Downtown Toronto Regent Park\n",
"6 M6A North York Lawrence Heights"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#drop rows with no borough\n",
"df = df.loc[df['Borough'] != 'Not assigned']\n",
"df.head(5)"
]
},
{
"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>PostalCode</th>\n",
" <th>Borough</th>\n",
" <th>Neighbourhood</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>Harbourfront</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" PostalCode Borough Neighbourhood\n",
"0 M3A North York Parkwoods\n",
"1 M4A North York Victoria Village\n",
"2 M5A Downtown Toronto Harbourfront"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.reset_index(drop=True, inplace=True) #RESET INDEX AFTER DELETING COLUMNS\n",
"df.head(3)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"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>Neighbourhood</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>Scarborough</td>\n",
" <td>Malvern,Rouge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1C</th>\n",
" <td>Scarborough</td>\n",
" <td>Highland Creek,Rouge Hill,Port Union</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1E</th>\n",
" <td>Scarborough</td>\n",
" <td>Morningside,Guildwood,West Hill</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1G</th>\n",
" <td>Scarborough</td>\n",
" <td>Woburn</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1H</th>\n",
" <td>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1J</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1K</th>\n",
" <td>Scarborough</td>\n",
" <td>Ionview,Kennedy Park,East Birchmount Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1L</th>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile,Clairlea,Oakridge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1M</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside,Scarborough Village West,Cliffcrest</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1N</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside West,Birch Cliff</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1P</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Town Centre,Wexford Heights,Dorset...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1R</th>\n",
" <td>Scarborough</td>\n",
" <td>Wexford,Maryvale</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1S</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1T</th>\n",
" <td>Scarborough</td>\n",
" <td>Sullivan,Clarks Corners,Tam O'Shanter</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1V</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt North,Steeles East,L'Amoreaux East,M...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Borough Neighbourhood\n",
"PostalCode \n",
"M1B Scarborough Malvern,Rouge\n",
"M1C Scarborough Highland Creek,Rouge Hill,Port Union\n",
"M1E Scarborough Morningside,Guildwood,West Hill\n",
"M1G Scarborough Woburn\n",
"M1H Scarborough Cedarbrae\n",
"M1J Scarborough Scarborough Village\n",
"M1K Scarborough Ionview,Kennedy Park,East Birchmount Park\n",
"M1L Scarborough Golden Mile,Clairlea,Oakridge\n",
"M1M Scarborough Cliffside,Scarborough Village West,Cliffcrest\n",
"M1N Scarborough Cliffside West,Birch Cliff\n",
"M1P Scarborough Scarborough Town Centre,Wexford Heights,Dorset...\n",
"M1R Scarborough Wexford,Maryvale\n",
"M1S Scarborough Agincourt\n",
"M1T Scarborough Sullivan,Clarks Corners,Tam O'Shanter\n",
"M1V Scarborough Agincourt North,Steeles East,L'Amoreaux East,M..."
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.agg.html\n",
"j = ',' #joiner\n",
"#lambda function\n",
"#as_index false to leave numbers\n",
"df = df.groupby(by='PostalCode', as_index=True).agg(lambda x: j.join(set(x.dropna())))\n",
"df.head(15)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"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>Neighbourhood</th>\n",
" <th>Neighborhood</th>\n",
" </tr>\n",
" <tr>\n",
" <th>PostalCode</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>M1B</th>\n",
" <td>Scarborough</td>\n",
" <td>Malvern,Rouge</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1C</th>\n",
" <td>Scarborough</td>\n",
" <td>Highland Creek,Rouge Hill,Port Union</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1E</th>\n",
" <td>Scarborough</td>\n",
" <td>Morningside,Guildwood,West Hill</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1G</th>\n",
" <td>Scarborough</td>\n",
" <td>Woburn</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1H</th>\n",
" <td>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1J</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1K</th>\n",
" <td>Scarborough</td>\n",
" <td>Ionview,Kennedy Park,East Birchmount Park</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1L</th>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile,Clairlea,Oakridge</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1M</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside,Scarborough Village West,Cliffcrest</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1N</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside West,Birch Cliff</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1P</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Town Centre,Wexford Heights,Dorset...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1R</th>\n",
" <td>Scarborough</td>\n",
" <td>Wexford,Maryvale</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1S</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1T</th>\n",
" <td>Scarborough</td>\n",
" <td>Sullivan,Clarks Corners,Tam O'Shanter</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1V</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt North,Steeles East,L'Amoreaux East,M...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1W</th>\n",
" <td>Scarborough</td>\n",
" <td>L'Amoreaux West,Steeles West</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1X</th>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2H</th>\n",
" <td>North York</td>\n",
" <td>Hillcrest Village</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2J</th>\n",
" <td>North York</td>\n",
" <td>Fairview,Oriole,Henry Farm</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2K</th>\n",
" <td>North York</td>\n",
" <td>Bayview Village</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2L</th>\n",
" <td>North York</td>\n",
" <td>Silver Hills,York Mills</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2M</th>\n",
" <td>North York</td>\n",
" <td>Willowdale,Newtonbrook</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2N</th>\n",
" <td>North York</td>\n",
" <td>Willowdale South</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2P</th>\n",
" <td>North York</td>\n",
" <td>York Mills West</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2R</th>\n",
" <td>North York</td>\n",
" <td>Willowdale West</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3A</th>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3B</th>\n",
" <td>North York</td>\n",
" <td>Don Mills North</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3C</th>\n",
" <td>North York</td>\n",
" <td>Don Mills South,Flemingdon Park</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3H</th>\n",
" <td>North York</td>\n",
" <td>Downsview North,Wilson Heights,Bathurst Manor</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3J</th>\n",
" <td>North York</td>\n",
" <td>Northwood Park,York University</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6C</th>\n",
" <td>York</td>\n",
" <td>Humewood-Cedarvale</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6E</th>\n",
" <td>York</td>\n",
" <td>Caledonia-Fairbanks</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6G</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Christie</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6H</th>\n",
" <td>West Toronto</td>\n",
" <td>Dovercourt Village,Dufferin</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6J</th>\n",
" <td>West Toronto</td>\n",
" <td>Little Portugal,Trinity</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6K</th>\n",
" <td>West Toronto</td>\n",
" <td>Exhibition Place,Parkdale Village,Brockton</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6L</th>\n",
" <td>North York</td>\n",
" <td>Upwood Park,North Park,Maple Leaf Park</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6M</th>\n",
" <td>York</td>\n",
" <td>Silverthorn,Mount Dennis,Keelesdale,Del Ray</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6N</th>\n",
" <td>York</td>\n",
" <td>The Junction North,Runnymede</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6P</th>\n",
" <td>West Toronto</td>\n",
" <td>High Park,The Junction South</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6R</th>\n",
" <td>West Toronto</td>\n",
" <td>Parkdale,Roncesvalles</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6S</th>\n",
" <td>West Toronto</td>\n",
" <td>Swansea,Runnymede</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7A</th>\n",
" <td>Queen's Park</td>\n",
" <td>Queen's Park</td>\n",
" <td>Queen's Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7R</th>\n",
" <td>Mississauga</td>\n",
" <td>Canada Post Gateway Processing Centre</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7Y</th>\n",
" <td>East Toronto</td>\n",
" <td>Business Reply Mail Processing Centre 969 Eastern</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8V</th>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico South,New Toronto,Humber Bay Shores</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8W</th>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood,Long Branch</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8X</th>\n",
" <td>Etobicoke</td>\n",
" <td>The Kingsway,Montgomery Road,Old Mill North</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8Y</th>\n",
" <td>Etobicoke</td>\n",
" <td>Sunnylea,Kingsway Park South East,Mimico NE,Th...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8Z</th>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West,The Queensway West,Mi...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9A</th>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9B</th>\n",
" <td>Etobicoke</td>\n",
" <td>Princess Gardens,West Deane Park,Martin Grove,...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9C</th>\n",
" <td>Etobicoke</td>\n",
" <td>Markland Wood,Old Burnhamthorpe,Bloordale Gard...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9L</th>\n",
" <td>North York</td>\n",
" <td>Humber Summit</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9M</th>\n",
" <td>North York</td>\n",
" <td>Emery,Humberlea</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9N</th>\n",
" <td>York</td>\n",
" <td>Weston</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9P</th>\n",
" <td>Etobicoke</td>\n",
" <td>Westmount</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9R</th>\n",
" <td>Etobicoke</td>\n",
" <td>Richview Gardens,Kingsview Village,St. Phillip...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9V</th>\n",
" <td>Etobicoke</td>\n",
" <td>Mount Olive,South Steeles,Thistletown,Silverst...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9W</th>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>103 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Borough \\\n",
"PostalCode \n",
"M1B Scarborough \n",
"M1C Scarborough \n",
"M1E Scarborough \n",
"M1G Scarborough \n",
"M1H Scarborough \n",
"M1J Scarborough \n",
"M1K Scarborough \n",
"M1L Scarborough \n",
"M1M Scarborough \n",
"M1N Scarborough \n",
"M1P Scarborough \n",
"M1R Scarborough \n",
"M1S Scarborough \n",
"M1T Scarborough \n",
"M1V Scarborough \n",
"M1W Scarborough \n",
"M1X Scarborough \n",
"M2H North York \n",
"M2J North York \n",
"M2K North York \n",
"M2L North York \n",
"M2M North York \n",
"M2N North York \n",
"M2P North York \n",
"M2R North York \n",
"M3A North York \n",
"M3B North York \n",
"M3C North York \n",
"M3H North York \n",
"M3J North York \n",
"... ... \n",
"M6C York \n",
"M6E York \n",
"M6G Downtown Toronto \n",
"M6H West Toronto \n",
"M6J West Toronto \n",
"M6K West Toronto \n",
"M6L North York \n",
"M6M York \n",
"M6N York \n",
"M6P West Toronto \n",
"M6R West Toronto \n",
"M6S West Toronto \n",
"M7A Queen's Park \n",
"M7R Mississauga \n",
"M7Y East Toronto \n",
"M8V Etobicoke \n",
"M8W Etobicoke \n",
"M8X Etobicoke \n",
"M8Y Etobicoke \n",
"M8Z Etobicoke \n",
"M9A Etobicoke \n",
"M9B Etobicoke \n",
"M9C Etobicoke \n",
"M9L North York \n",
"M9M North York \n",
"M9N York \n",
"M9P Etobicoke \n",
"M9R Etobicoke \n",
"M9V Etobicoke \n",
"M9W Etobicoke \n",
"\n",
" Neighbourhood Neighborhood \n",
"PostalCode \n",
"M1B Malvern,Rouge NaN \n",
"M1C Highland Creek,Rouge Hill,Port Union NaN \n",
"M1E Morningside,Guildwood,West Hill NaN \n",
"M1G Woburn NaN \n",
"M1H Cedarbrae NaN \n",
"M1J Scarborough Village NaN \n",
"M1K Ionview,Kennedy Park,East Birchmount Park NaN \n",
"M1L Golden Mile,Clairlea,Oakridge NaN \n",
"M1M Cliffside,Scarborough Village West,Cliffcrest NaN \n",
"M1N Cliffside West,Birch Cliff NaN \n",
"M1P Scarborough Town Centre,Wexford Heights,Dorset... NaN \n",
"M1R Wexford,Maryvale NaN \n",
"M1S Agincourt NaN \n",
"M1T Sullivan,Clarks Corners,Tam O'Shanter NaN \n",
"M1V Agincourt North,Steeles East,L'Amoreaux East,M... NaN \n",
"M1W L'Amoreaux West,Steeles West NaN \n",
"M1X Upper Rouge NaN \n",
"M2H Hillcrest Village NaN \n",
"M2J Fairview,Oriole,Henry Farm NaN \n",
"M2K Bayview Village NaN \n",
"M2L Silver Hills,York Mills NaN \n",
"M2M Willowdale,Newtonbrook NaN \n",
"M2N Willowdale South NaN \n",
"M2P York Mills West NaN \n",
"M2R Willowdale West NaN \n",
"M3A Parkwoods NaN \n",
"M3B Don Mills North NaN \n",
"M3C Don Mills South,Flemingdon Park NaN \n",
"M3H Downsview North,Wilson Heights,Bathurst Manor NaN \n",
"M3J Northwood Park,York University NaN \n",
"... ... ... \n",
"M6C Humewood-Cedarvale NaN \n",
"M6E Caledonia-Fairbanks NaN \n",
"M6G Christie NaN \n",
"M6H Dovercourt Village,Dufferin NaN \n",
"M6J Little Portugal,Trinity NaN \n",
"M6K Exhibition Place,Parkdale Village,Brockton NaN \n",
"M6L Upwood Park,North Park,Maple Leaf Park NaN \n",
"M6M Silverthorn,Mount Dennis,Keelesdale,Del Ray NaN \n",
"M6N The Junction North,Runnymede NaN \n",
"M6P High Park,The Junction South NaN \n",
"M6R Parkdale,Roncesvalles NaN \n",
"M6S Swansea,Runnymede NaN \n",
"M7A Queen's Park Queen's Park \n",
"M7R Canada Post Gateway Processing Centre NaN \n",
"M7Y Business Reply Mail Processing Centre 969 Eastern NaN \n",
"M8V Mimico South,New Toronto,Humber Bay Shores NaN \n",
"M8W Alderwood,Long Branch NaN \n",
"M8X The Kingsway,Montgomery Road,Old Mill North NaN \n",
"M8Y Sunnylea,Kingsway Park South East,Mimico NE,Th... NaN \n",
"M8Z Kingsway Park South West,The Queensway West,Mi... NaN \n",
"M9A Islington Avenue NaN \n",
"M9B Princess Gardens,West Deane Park,Martin Grove,... NaN \n",
"M9C Markland Wood,Old Burnhamthorpe,Bloordale Gard... NaN \n",
"M9L Humber Summit NaN \n",
"M9M Emery,Humberlea NaN \n",
"M9N Weston NaN \n",
"M9P Westmount NaN \n",
"M9R Richview Gardens,Kingsview Village,St. Phillip... NaN \n",
"M9V Mount Olive,South Steeles,Thistletown,Silverst... NaN \n",
"M9W Northwest NaN \n",
"\n",
"[103 rows x 3 columns]"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df['Neighbourhood'] == 'Not assigned', 'Neighbourhood' ] = df['Borough']\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(103, 3)"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"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>Borough</th>\n",
" <th>Neighbourhood</th>\n",
" <th>Neighborhood</th>\n",
" </tr>\n",
" <tr>\n",
" <th>PostalCode</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>M1B</th>\n",
" <td>Scarborough</td>\n",
" <td>Malvern,Rouge</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1C</th>\n",
" <td>Scarborough</td>\n",
" <td>Highland Creek,Rouge Hill,Port Union</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1E</th>\n",
" <td>Scarborough</td>\n",
" <td>Morningside,Guildwood,West Hill</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1G</th>\n",
" <td>Scarborough</td>\n",
" <td>Woburn</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1H</th>\n",
" <td>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1J</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1K</th>\n",
" <td>Scarborough</td>\n",
" <td>Ionview,Kennedy Park,East Birchmount Park</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1L</th>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile,Clairlea,Oakridge</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1M</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside,Scarborough Village West,Cliffcrest</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1N</th>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside West,Birch Cliff</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1P</th>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Town Centre,Wexford Heights,Dorset...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1R</th>\n",
" <td>Scarborough</td>\n",
" <td>Wexford,Maryvale</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1S</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1T</th>\n",
" <td>Scarborough</td>\n",
" <td>Sullivan,Clarks Corners,Tam O'Shanter</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1V</th>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt North,Steeles East,L'Amoreaux East,M...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1W</th>\n",
" <td>Scarborough</td>\n",
" <td>L'Amoreaux West,Steeles West</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M1X</th>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2H</th>\n",
" <td>North York</td>\n",
" <td>Hillcrest Village</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2J</th>\n",
" <td>North York</td>\n",
" <td>Fairview,Oriole,Henry Farm</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2K</th>\n",
" <td>North York</td>\n",
" <td>Bayview Village</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2L</th>\n",
" <td>North York</td>\n",
" <td>Silver Hills,York Mills</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2M</th>\n",
" <td>North York</td>\n",
" <td>Willowdale,Newtonbrook</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2N</th>\n",
" <td>North York</td>\n",
" <td>Willowdale South</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2P</th>\n",
" <td>North York</td>\n",
" <td>York Mills West</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M2R</th>\n",
" <td>North York</td>\n",
" <td>Willowdale West</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3A</th>\n",
" <td>North York</td>\n",
" <td>Parkwoods</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3B</th>\n",
" <td>North York</td>\n",
" <td>Don Mills North</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3C</th>\n",
" <td>North York</td>\n",
" <td>Don Mills South,Flemingdon Park</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3H</th>\n",
" <td>North York</td>\n",
" <td>Downsview North,Wilson Heights,Bathurst Manor</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M3J</th>\n",
" <td>North York</td>\n",
" <td>Northwood Park,York University</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6C</th>\n",
" <td>York</td>\n",
" <td>Humewood-Cedarvale</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6E</th>\n",
" <td>York</td>\n",
" <td>Caledonia-Fairbanks</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6G</th>\n",
" <td>Downtown Toronto</td>\n",
" <td>Christie</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6H</th>\n",
" <td>West Toronto</td>\n",
" <td>Dovercourt Village,Dufferin</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6J</th>\n",
" <td>West Toronto</td>\n",
" <td>Little Portugal,Trinity</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6K</th>\n",
" <td>West Toronto</td>\n",
" <td>Exhibition Place,Parkdale Village,Brockton</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6L</th>\n",
" <td>North York</td>\n",
" <td>Upwood Park,North Park,Maple Leaf Park</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6M</th>\n",
" <td>York</td>\n",
" <td>Silverthorn,Mount Dennis,Keelesdale,Del Ray</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6N</th>\n",
" <td>York</td>\n",
" <td>The Junction North,Runnymede</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6P</th>\n",
" <td>West Toronto</td>\n",
" <td>High Park,The Junction South</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6R</th>\n",
" <td>West Toronto</td>\n",
" <td>Parkdale,Roncesvalles</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M6S</th>\n",
" <td>West Toronto</td>\n",
" <td>Swansea,Runnymede</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7A</th>\n",
" <td>Queen's Park</td>\n",
" <td>Queen's Park</td>\n",
" <td>Queen's Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7R</th>\n",
" <td>Mississauga</td>\n",
" <td>Canada Post Gateway Processing Centre</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M7Y</th>\n",
" <td>East Toronto</td>\n",
" <td>Business Reply Mail Processing Centre 969 Eastern</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8V</th>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico South,New Toronto,Humber Bay Shores</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8W</th>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood,Long Branch</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8X</th>\n",
" <td>Etobicoke</td>\n",
" <td>The Kingsway,Montgomery Road,Old Mill North</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8Y</th>\n",
" <td>Etobicoke</td>\n",
" <td>Sunnylea,Kingsway Park South East,Mimico NE,Th...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M8Z</th>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West,The Queensway West,Mi...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9A</th>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9B</th>\n",
" <td>Etobicoke</td>\n",
" <td>Princess Gardens,West Deane Park,Martin Grove,...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9C</th>\n",
" <td>Etobicoke</td>\n",
" <td>Markland Wood,Old Burnhamthorpe,Bloordale Gard...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9L</th>\n",
" <td>North York</td>\n",
" <td>Humber Summit</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9M</th>\n",
" <td>North York</td>\n",
" <td>Emery,Humberlea</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9N</th>\n",
" <td>York</td>\n",
" <td>Weston</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9P</th>\n",
" <td>Etobicoke</td>\n",
" <td>Westmount</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9R</th>\n",
" <td>Etobicoke</td>\n",
" <td>Richview Gardens,Kingsview Village,St. Phillip...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9V</th>\n",
" <td>Etobicoke</td>\n",
" <td>Mount Olive,South Steeles,Thistletown,Silverst...</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>M9W</th>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>103 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Borough \\\n",
"PostalCode \n",
"M1B Scarborough \n",
"M1C Scarborough \n",
"M1E Scarborough \n",
"M1G Scarborough \n",
"M1H Scarborough \n",
"M1J Scarborough \n",
"M1K Scarborough \n",
"M1L Scarborough \n",
"M1M Scarborough \n",
"M1N Scarborough \n",
"M1P Scarborough \n",
"M1R Scarborough \n",
"M1S Scarborough \n",
"M1T Scarborough \n",
"M1V Scarborough \n",
"M1W Scarborough \n",
"M1X Scarborough \n",
"M2H North York \n",
"M2J North York \n",
"M2K North York \n",
"M2L North York \n",
"M2M North York \n",
"M2N North York \n",
"M2P North York \n",
"M2R North York \n",
"M3A North York \n",
"M3B North York \n",
"M3C North York \n",
"M3H North York \n",
"M3J North York \n",
"... ... \n",
"M6C York \n",
"M6E York \n",
"M6G Downtown Toronto \n",
"M6H West Toronto \n",
"M6J West Toronto \n",
"M6K West Toronto \n",
"M6L North York \n",
"M6M York \n",
"M6N York \n",
"M6P West Toronto \n",
"M6R West Toronto \n",
"M6S West Toronto \n",
"M7A Queen's Park \n",
"M7R Mississauga \n",
"M7Y East Toronto \n",
"M8V Etobicoke \n",
"M8W Etobicoke \n",
"M8X Etobicoke \n",
"M8Y Etobicoke \n",
"M8Z Etobicoke \n",
"M9A Etobicoke \n",
"M9B Etobicoke \n",
"M9C Etobicoke \n",
"M9L North York \n",
"M9M North York \n",
"M9N York \n",
"M9P Etobicoke \n",
"M9R Etobicoke \n",
"M9V Etobicoke \n",
"M9W Etobicoke \n",
"\n",
" Neighbourhood Neighborhood \n",
"PostalCode \n",
"M1B Malvern,Rouge NaN \n",
"M1C Highland Creek,Rouge Hill,Port Union NaN \n",
"M1E Morningside,Guildwood,West Hill NaN \n",
"M1G Woburn NaN \n",
"M1H Cedarbrae NaN \n",
"M1J Scarborough Village NaN \n",
"M1K Ionview,Kennedy Park,East Birchmount Park NaN \n",
"M1L Golden Mile,Clairlea,Oakridge NaN \n",
"M1M Cliffside,Scarborough Village West,Cliffcrest NaN \n",
"M1N Cliffside West,Birch Cliff NaN \n",
"M1P Scarborough Town Centre,Wexford Heights,Dorset... NaN \n",
"M1R Wexford,Maryvale NaN \n",
"M1S Agincourt NaN \n",
"M1T Sullivan,Clarks Corners,Tam O'Shanter NaN \n",
"M1V Agincourt North,Steeles East,L'Amoreaux East,M... NaN \n",
"M1W L'Amoreaux West,Steeles West NaN \n",
"M1X Upper Rouge NaN \n",
"M2H Hillcrest Village NaN \n",
"M2J Fairview,Oriole,Henry Farm NaN \n",
"M2K Bayview Village NaN \n",
"M2L Silver Hills,York Mills NaN \n",
"M2M Willowdale,Newtonbrook NaN \n",
"M2N Willowdale South NaN \n",
"M2P York Mills West NaN \n",
"M2R Willowdale West NaN \n",
"M3A Parkwoods NaN \n",
"M3B Don Mills North NaN \n",
"M3C Don Mills South,Flemingdon Park NaN \n",
"M3H Downsview North,Wilson Heights,Bathurst Manor NaN \n",
"M3J Northwood Park,York University NaN \n",
"... ... ... \n",
"M6C Humewood-Cedarvale NaN \n",
"M6E Caledonia-Fairbanks NaN \n",
"M6G Christie NaN \n",
"M6H Dovercourt Village,Dufferin NaN \n",
"M6J Little Portugal,Trinity NaN \n",
"M6K Exhibition Place,Parkdale Village,Brockton NaN \n",
"M6L Upwood Park,North Park,Maple Leaf Park NaN \n",
"M6M Silverthorn,Mount Dennis,Keelesdale,Del Ray NaN \n",
"M6N The Junction North,Runnymede NaN \n",
"M6P High Park,The Junction South NaN \n",
"M6R Parkdale,Roncesvalles NaN \n",
"M6S Swansea,Runnymede NaN \n",
"M7A Queen's Park Queen's Park \n",
"M7R Canada Post Gateway Processing Centre NaN \n",
"M7Y Business Reply Mail Processing Centre 969 Eastern NaN \n",
"M8V Mimico South,New Toronto,Humber Bay Shores NaN \n",
"M8W Alderwood,Long Branch NaN \n",
"M8X The Kingsway,Montgomery Road,Old Mill North NaN \n",
"M8Y Sunnylea,Kingsway Park South East,Mimico NE,Th... NaN \n",
"M8Z Kingsway Park South West,The Queensway West,Mi... NaN \n",
"M9A Islington Avenue NaN \n",
"M9B Princess Gardens,West Deane Park,Martin Grove,... NaN \n",
"M9C Markland Wood,Old Burnhamthorpe,Bloordale Gard... NaN \n",
"M9L Humber Summit NaN \n",
"M9M Emery,Humberlea NaN \n",
"M9N Weston NaN \n",
"M9P Westmount NaN \n",
"M9R Richview Gardens,Kingsview Village,St. Phillip... NaN \n",
"M9V Mount Olive,South Steeles,Thistletown,Silverst... NaN \n",
"M9W Northwest NaN \n",
"\n",
"[103 rows x 3 columns]"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment