Skip to content

Instantly share code, notes, and snippets.

@alfredo-g-zapiola
Created March 19, 2019 19:02
Show Gist options
  • Save alfredo-g-zapiola/6ec0a3796a13018a7adc206e7b18a89d to your computer and use it in GitHub Desktop.
Save alfredo-g-zapiola/6ec0a3796a13018a7adc206e7b18a89d 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": [
"SECOND PART\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"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>M1B</td>\n",
" <td>Scarborough</td>\n",
" <td>Malvern,Rouge</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>Morningside,Guildwood,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>Ionview,Kennedy Park,East Birchmount Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>M1L</td>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile,Clairlea,Oakridge</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>M1M</td>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside,Scarborough Village West,Cliffcrest</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>M1N</td>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside West,Birch Cliff</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>M1P</td>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Town Centre,Wexford Heights,Dorset...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>M1R</td>\n",
" <td>Scarborough</td>\n",
" <td>Wexford,Maryvale</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>Sullivan,Clarks Corners,Tam O'Shanter</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>M1V</td>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt North,Steeles East,L'Amoreaux East,M...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>M1W</td>\n",
" <td>Scarborough</td>\n",
" <td>L'Amoreaux West,Steeles 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,Oriole,Henry Farm</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>Willowdale,Newtonbrook</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>Don Mills South,Flemingdon Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>M3H</td>\n",
" <td>North York</td>\n",
" <td>Downsview North,Wilson Heights,Bathurst Manor</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>Exhibition Place,Parkdale Village,Brockton</td>\n",
" </tr>\n",
" <tr>\n",
" <th>79</th>\n",
" <td>M6L</td>\n",
" <td>North York</td>\n",
" <td>Upwood Park,North Park,Maple Leaf Park</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>M6M</td>\n",
" <td>York</td>\n",
" <td>Silverthorn,Mount Dennis,Keelesdale,Del Ray</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>Swansea,Runnymede</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>Mimico South,New Toronto,Humber Bay Shores</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>Sunnylea,Kingsway Park South East,Mimico NE,Th...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West,The Queensway West,Mi...</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>Princess Gardens,West Deane Park,Martin Grove,...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>M9C</td>\n",
" <td>Etobicoke</td>\n",
" <td>Markland Wood,Old Burnhamthorpe,Bloordale Gard...</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>Richview Gardens,Kingsview Village,St. Phillip...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>M9V</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mount Olive,South Steeles,Thistletown,Silverst...</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": [
" PostalCode 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 Malvern,Rouge \n",
"1 Highland Creek,Rouge Hill,Port Union \n",
"2 Morningside,Guildwood,West Hill \n",
"3 Woburn \n",
"4 Cedarbrae \n",
"5 Scarborough Village \n",
"6 Ionview,Kennedy Park,East Birchmount Park \n",
"7 Golden Mile,Clairlea,Oakridge \n",
"8 Cliffside,Scarborough Village West,Cliffcrest \n",
"9 Cliffside West,Birch Cliff \n",
"10 Scarborough Town Centre,Wexford Heights,Dorset... \n",
"11 Wexford,Maryvale \n",
"12 Agincourt \n",
"13 Sullivan,Clarks Corners,Tam O'Shanter \n",
"14 Agincourt North,Steeles East,L'Amoreaux East,M... \n",
"15 L'Amoreaux West,Steeles West \n",
"16 Upper Rouge \n",
"17 Hillcrest Village \n",
"18 Fairview,Oriole,Henry Farm \n",
"19 Bayview Village \n",
"20 Silver Hills,York Mills \n",
"21 Willowdale,Newtonbrook \n",
"22 Willowdale South \n",
"23 York Mills West \n",
"24 Willowdale West \n",
"25 Parkwoods \n",
"26 Don Mills North \n",
"27 Don Mills South,Flemingdon Park \n",
"28 Downsview North,Wilson Heights,Bathurst Manor \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 Exhibition Place,Parkdale Village,Brockton \n",
"79 Upwood Park,North Park,Maple Leaf Park \n",
"80 Silverthorn,Mount Dennis,Keelesdale,Del Ray \n",
"81 The Junction North,Runnymede \n",
"82 High Park,The Junction South \n",
"83 Parkdale,Roncesvalles \n",
"84 Swansea,Runnymede \n",
"85 Queen's Park \n",
"86 Canada Post Gateway Processing Centre \n",
"87 Business Reply Mail Processing Centre 969 Eastern \n",
"88 Mimico South,New Toronto,Humber Bay Shores \n",
"89 Alderwood,Long Branch \n",
"90 The Kingsway,Montgomery Road,Old Mill North \n",
"91 Sunnylea,Kingsway Park South East,Mimico NE,Th... \n",
"92 Kingsway Park South West,The Queensway West,Mi... \n",
"93 Islington Avenue \n",
"94 Princess Gardens,West Deane Park,Martin Grove,... \n",
"95 Markland Wood,Old Burnhamthorpe,Bloordale Gard... \n",
"96 Humber Summit \n",
"97 Emery,Humberlea \n",
"98 Weston \n",
"99 Westmount \n",
"100 Richview Gardens,Kingsview Village,St. Phillip... \n",
"101 Mount Olive,South Steeles,Thistletown,Silverst... \n",
"102 Northwest \n",
"\n",
"[103 rows x 3 columns]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"df0 = pd.read_csv(\"TorontoZIP.csv\")\n",
"df0"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"DONE\n"
]
}
],
"source": [
"#!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",
"#!conda install -c conda-forge geocoder --yes\n",
"import geocoder # import geocoder \n",
"print('DONE')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#IF DOES NOT WORK, CONTINUE\n",
"'''\n",
"df = df0\n",
"df['Latitude'] = np.nan\n",
"df['Longitude'] = np.nan\n",
"\n",
"# loop until you get the coordinates\n",
"for zipc in df0['PostalCode'].unique():\n",
" # initialize your variable to None\n",
" lat_lng_coords = None\n",
" while(lat_lng_coords is None):\n",
" try:\n",
" g = geocoder.google('{}, Toronto, Ontario'.format(zipc))\n",
" lat_lng_coords = g.latlng\n",
" latitude = lat_lng_coords[0]\n",
" longitude = lat_lng_coords[1]\n",
" except: continue\n",
" df.loc[df['PostalCode'] == zipc, 'Latitude'] = latitude\n",
" df.loc[df['PostalCode'] == zipc, 'Longitude'] = longitude\n",
"'''\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['Postal Code', 'Latitude', 'Longitude'], dtype='object')\n"
]
},
{
"data": {
"text/plain": [
"Index(['PostalCode', 'Latitude', 'Longitude'], dtype='object')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2 = pd.read_csv('Geospatial_Coordinates.csv')\n",
"print(df2.columns)\n",
"df2.columns = ['PostalCode', 'Latitude', 'Longitude']\n",
"df2.columns"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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",
" <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>Scarborough</td>\n",
" <td>Malvern,Rouge</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>Scarborough</td>\n",
" <td>Highland Creek,Rouge Hill,Port Union</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>Scarborough</td>\n",
" <td>Morningside,Guildwood,West Hill</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>Scarborough</td>\n",
" <td>Woburn</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>Scarborough</td>\n",
" <td>Cedarbrae</td>\n",
" <td>43.773136</td>\n",
" <td>-79.239476</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>M1J</td>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Village</td>\n",
" <td>43.744734</td>\n",
" <td>-79.239476</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>M1K</td>\n",
" <td>Scarborough</td>\n",
" <td>Ionview,Kennedy Park,East Birchmount Park</td>\n",
" <td>43.727929</td>\n",
" <td>-79.262029</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>M1L</td>\n",
" <td>Scarborough</td>\n",
" <td>Golden Mile,Clairlea,Oakridge</td>\n",
" <td>43.711112</td>\n",
" <td>-79.284577</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>M1M</td>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside,Scarborough Village West,Cliffcrest</td>\n",
" <td>43.716316</td>\n",
" <td>-79.239476</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>M1N</td>\n",
" <td>Scarborough</td>\n",
" <td>Cliffside West,Birch Cliff</td>\n",
" <td>43.692657</td>\n",
" <td>-79.264848</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>M1P</td>\n",
" <td>Scarborough</td>\n",
" <td>Scarborough Town Centre,Wexford Heights,Dorset...</td>\n",
" <td>43.757410</td>\n",
" <td>-79.273304</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>M1R</td>\n",
" <td>Scarborough</td>\n",
" <td>Wexford,Maryvale</td>\n",
" <td>43.750072</td>\n",
" <td>-79.295849</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>M1S</td>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt</td>\n",
" <td>43.794200</td>\n",
" <td>-79.262029</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>M1T</td>\n",
" <td>Scarborough</td>\n",
" <td>Sullivan,Clarks Corners,Tam O'Shanter</td>\n",
" <td>43.781638</td>\n",
" <td>-79.304302</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>M1V</td>\n",
" <td>Scarborough</td>\n",
" <td>Agincourt North,Steeles East,L'Amoreaux East,M...</td>\n",
" <td>43.815252</td>\n",
" <td>-79.284577</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>M1W</td>\n",
" <td>Scarborough</td>\n",
" <td>L'Amoreaux West,Steeles West</td>\n",
" <td>43.799525</td>\n",
" <td>-79.318389</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>M1X</td>\n",
" <td>Scarborough</td>\n",
" <td>Upper Rouge</td>\n",
" <td>43.836125</td>\n",
" <td>-79.205636</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>M2H</td>\n",
" <td>North York</td>\n",
" <td>Hillcrest Village</td>\n",
" <td>43.803762</td>\n",
" <td>-79.363452</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>M2J</td>\n",
" <td>North York</td>\n",
" <td>Fairview,Oriole,Henry Farm</td>\n",
" <td>43.778517</td>\n",
" <td>-79.346556</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>M2K</td>\n",
" <td>North York</td>\n",
" <td>Bayview Village</td>\n",
" <td>43.786947</td>\n",
" <td>-79.385975</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",
" <td>43.757490</td>\n",
" <td>-79.374714</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>M2M</td>\n",
" <td>North York</td>\n",
" <td>Willowdale,Newtonbrook</td>\n",
" <td>43.789053</td>\n",
" <td>-79.408493</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>M2N</td>\n",
" <td>North York</td>\n",
" <td>Willowdale South</td>\n",
" <td>43.770120</td>\n",
" <td>-79.408493</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",
" <td>43.752758</td>\n",
" <td>-79.400049</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>M2R</td>\n",
" <td>North York</td>\n",
" <td>Willowdale West</td>\n",
" <td>43.782736</td>\n",
" <td>-79.442259</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</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>26</th>\n",
" <td>M3B</td>\n",
" <td>North York</td>\n",
" <td>Don Mills North</td>\n",
" <td>43.745906</td>\n",
" <td>-79.352188</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>M3C</td>\n",
" <td>North York</td>\n",
" <td>Don Mills South,Flemingdon Park</td>\n",
" <td>43.725900</td>\n",
" <td>-79.340923</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>M3H</td>\n",
" <td>North York</td>\n",
" <td>Downsview North,Wilson Heights,Bathurst Manor</td>\n",
" <td>43.754328</td>\n",
" <td>-79.442259</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",
" <td>43.767980</td>\n",
" <td>-79.487262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\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",
" <td>43.693781</td>\n",
" <td>-79.428191</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>M6E</td>\n",
" <td>York</td>\n",
" <td>Caledonia-Fairbanks</td>\n",
" <td>43.689026</td>\n",
" <td>-79.453512</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75</th>\n",
" <td>M6G</td>\n",
" <td>Downtown Toronto</td>\n",
" <td>Christie</td>\n",
" <td>43.669542</td>\n",
" <td>-79.422564</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",
" <td>43.669005</td>\n",
" <td>-79.442259</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",
" <td>43.647927</td>\n",
" <td>-79.419750</td>\n",
" </tr>\n",
" <tr>\n",
" <th>78</th>\n",
" <td>M6K</td>\n",
" <td>West Toronto</td>\n",
" <td>Exhibition Place,Parkdale Village,Brockton</td>\n",
" <td>43.636847</td>\n",
" <td>-79.428191</td>\n",
" </tr>\n",
" <tr>\n",
" <th>79</th>\n",
" <td>M6L</td>\n",
" <td>North York</td>\n",
" <td>Upwood Park,North Park,Maple Leaf Park</td>\n",
" <td>43.713756</td>\n",
" <td>-79.490074</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>M6M</td>\n",
" <td>York</td>\n",
" <td>Silverthorn,Mount Dennis,Keelesdale,Del Ray</td>\n",
" <td>43.691116</td>\n",
" <td>-79.476013</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",
" <td>43.673185</td>\n",
" <td>-79.487262</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",
" <td>43.661608</td>\n",
" <td>-79.464763</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>M6R</td>\n",
" <td>West Toronto</td>\n",
" <td>Parkdale,Roncesvalles</td>\n",
" <td>43.648960</td>\n",
" <td>-79.456325</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>M6S</td>\n",
" <td>West Toronto</td>\n",
" <td>Swansea,Runnymede</td>\n",
" <td>43.651571</td>\n",
" <td>-79.484450</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",
" <td>43.662301</td>\n",
" <td>-79.389494</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",
" <td>43.636966</td>\n",
" <td>-79.615819</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",
" <td>43.662744</td>\n",
" <td>-79.321558</td>\n",
" </tr>\n",
" <tr>\n",
" <th>88</th>\n",
" <td>M8V</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mimico South,New Toronto,Humber Bay Shores</td>\n",
" <td>43.605647</td>\n",
" <td>-79.501321</td>\n",
" </tr>\n",
" <tr>\n",
" <th>89</th>\n",
" <td>M8W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Alderwood,Long Branch</td>\n",
" <td>43.602414</td>\n",
" <td>-79.543484</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",
" <td>43.653654</td>\n",
" <td>-79.506944</td>\n",
" </tr>\n",
" <tr>\n",
" <th>91</th>\n",
" <td>M8Y</td>\n",
" <td>Etobicoke</td>\n",
" <td>Sunnylea,Kingsway Park South East,Mimico NE,Th...</td>\n",
" <td>43.636258</td>\n",
" <td>-79.498509</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>M8Z</td>\n",
" <td>Etobicoke</td>\n",
" <td>Kingsway Park South West,The Queensway West,Mi...</td>\n",
" <td>43.628841</td>\n",
" <td>-79.520999</td>\n",
" </tr>\n",
" <tr>\n",
" <th>93</th>\n",
" <td>M9A</td>\n",
" <td>Etobicoke</td>\n",
" <td>Islington Avenue</td>\n",
" <td>43.667856</td>\n",
" <td>-79.532242</td>\n",
" </tr>\n",
" <tr>\n",
" <th>94</th>\n",
" <td>M9B</td>\n",
" <td>Etobicoke</td>\n",
" <td>Princess Gardens,West Deane Park,Martin Grove,...</td>\n",
" <td>43.650943</td>\n",
" <td>-79.554724</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
" <td>M9C</td>\n",
" <td>Etobicoke</td>\n",
" <td>Markland Wood,Old Burnhamthorpe,Bloordale Gard...</td>\n",
" <td>43.643515</td>\n",
" <td>-79.577201</td>\n",
" </tr>\n",
" <tr>\n",
" <th>96</th>\n",
" <td>M9L</td>\n",
" <td>North York</td>\n",
" <td>Humber Summit</td>\n",
" <td>43.756303</td>\n",
" <td>-79.565963</td>\n",
" </tr>\n",
" <tr>\n",
" <th>97</th>\n",
" <td>M9M</td>\n",
" <td>North York</td>\n",
" <td>Emery,Humberlea</td>\n",
" <td>43.724766</td>\n",
" <td>-79.532242</td>\n",
" </tr>\n",
" <tr>\n",
" <th>98</th>\n",
" <td>M9N</td>\n",
" <td>York</td>\n",
" <td>Weston</td>\n",
" <td>43.706876</td>\n",
" <td>-79.518188</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99</th>\n",
" <td>M9P</td>\n",
" <td>Etobicoke</td>\n",
" <td>Westmount</td>\n",
" <td>43.696319</td>\n",
" <td>-79.532242</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>M9R</td>\n",
" <td>Etobicoke</td>\n",
" <td>Richview Gardens,Kingsview Village,St. Phillip...</td>\n",
" <td>43.688905</td>\n",
" <td>-79.554724</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>M9V</td>\n",
" <td>Etobicoke</td>\n",
" <td>Mount Olive,South Steeles,Thistletown,Silverst...</td>\n",
" <td>43.739416</td>\n",
" <td>-79.588437</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>M9W</td>\n",
" <td>Etobicoke</td>\n",
" <td>Northwest</td>\n",
" <td>43.706748</td>\n",
" <td>-79.594054</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>103 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" PostalCode 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 Latitude Longitude \n",
"0 Malvern,Rouge 43.806686 -79.194353 \n",
"1 Highland Creek,Rouge Hill,Port Union 43.784535 -79.160497 \n",
"2 Morningside,Guildwood,West Hill 43.763573 -79.188711 \n",
"3 Woburn 43.770992 -79.216917 \n",
"4 Cedarbrae 43.773136 -79.239476 \n",
"5 Scarborough Village 43.744734 -79.239476 \n",
"6 Ionview,Kennedy Park,East Birchmount Park 43.727929 -79.262029 \n",
"7 Golden Mile,Clairlea,Oakridge 43.711112 -79.284577 \n",
"8 Cliffside,Scarborough Village West,Cliffcrest 43.716316 -79.239476 \n",
"9 Cliffside West,Birch Cliff 43.692657 -79.264848 \n",
"10 Scarborough Town Centre,Wexford Heights,Dorset... 43.757410 -79.273304 \n",
"11 Wexford,Maryvale 43.750072 -79.295849 \n",
"12 Agincourt 43.794200 -79.262029 \n",
"13 Sullivan,Clarks Corners,Tam O'Shanter 43.781638 -79.304302 \n",
"14 Agincourt North,Steeles East,L'Amoreaux East,M... 43.815252 -79.284577 \n",
"15 L'Amoreaux West,Steeles West 43.799525 -79.318389 \n",
"16 Upper Rouge 43.836125 -79.205636 \n",
"17 Hillcrest Village 43.803762 -79.363452 \n",
"18 Fairview,Oriole,Henry Farm 43.778517 -79.346556 \n",
"19 Bayview Village 43.786947 -79.385975 \n",
"20 Silver Hills,York Mills 43.757490 -79.374714 \n",
"21 Willowdale,Newtonbrook 43.789053 -79.408493 \n",
"22 Willowdale South 43.770120 -79.408493 \n",
"23 York Mills West 43.752758 -79.400049 \n",
"24 Willowdale West 43.782736 -79.442259 \n",
"25 Parkwoods 43.753259 -79.329656 \n",
"26 Don Mills North 43.745906 -79.352188 \n",
"27 Don Mills South,Flemingdon Park 43.725900 -79.340923 \n",
"28 Downsview North,Wilson Heights,Bathurst Manor 43.754328 -79.442259 \n",
"29 Northwood Park,York University 43.767980 -79.487262 \n",
".. ... ... ... \n",
"73 Humewood-Cedarvale 43.693781 -79.428191 \n",
"74 Caledonia-Fairbanks 43.689026 -79.453512 \n",
"75 Christie 43.669542 -79.422564 \n",
"76 Dovercourt Village,Dufferin 43.669005 -79.442259 \n",
"77 Little Portugal,Trinity 43.647927 -79.419750 \n",
"78 Exhibition Place,Parkdale Village,Brockton 43.636847 -79.428191 \n",
"79 Upwood Park,North Park,Maple Leaf Park 43.713756 -79.490074 \n",
"80 Silverthorn,Mount Dennis,Keelesdale,Del Ray 43.691116 -79.476013 \n",
"81 The Junction North,Runnymede 43.673185 -79.487262 \n",
"82 High Park,The Junction South 43.661608 -79.464763 \n",
"83 Parkdale,Roncesvalles 43.648960 -79.456325 \n",
"84 Swansea,Runnymede 43.651571 -79.484450 \n",
"85 Queen's Park 43.662301 -79.389494 \n",
"86 Canada Post Gateway Processing Centre 43.636966 -79.615819 \n",
"87 Business Reply Mail Processing Centre 969 Eastern 43.662744 -79.321558 \n",
"88 Mimico South,New Toronto,Humber Bay Shores 43.605647 -79.501321 \n",
"89 Alderwood,Long Branch 43.602414 -79.543484 \n",
"90 The Kingsway,Montgomery Road,Old Mill North 43.653654 -79.506944 \n",
"91 Sunnylea,Kingsway Park South East,Mimico NE,Th... 43.636258 -79.498509 \n",
"92 Kingsway Park South West,The Queensway West,Mi... 43.628841 -79.520999 \n",
"93 Islington Avenue 43.667856 -79.532242 \n",
"94 Princess Gardens,West Deane Park,Martin Grove,... 43.650943 -79.554724 \n",
"95 Markland Wood,Old Burnhamthorpe,Bloordale Gard... 43.643515 -79.577201 \n",
"96 Humber Summit 43.756303 -79.565963 \n",
"97 Emery,Humberlea 43.724766 -79.532242 \n",
"98 Weston 43.706876 -79.518188 \n",
"99 Westmount 43.696319 -79.532242 \n",
"100 Richview Gardens,Kingsview Village,St. Phillip... 43.688905 -79.554724 \n",
"101 Mount Olive,South Steeles,Thistletown,Silverst... 43.739416 -79.588437 \n",
"102 Northwest 43.706748 -79.594054 \n",
"\n",
"[103 rows x 5 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df0 = df0.merge(df2, on='PostalCode', how='left')\n",
"df0"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"df0.to_csv('TorontoZipLATLONG.csv')"
]
},
{
"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