diff --git a/Geospatial_Coordinates.csv b/Geospatial_Coordinates.csv new file mode 100644 index 0000000..d8c3222 --- /dev/null +++ b/Geospatial_Coordinates.csv @@ -0,0 +1,104 @@ +Postal Code,Latitude,Longitude +M1B,43.8066863,-79.1943534 +M1C,43.7845351,-79.1604971 +M1E,43.7635726,-79.1887115 +M1G,43.7709921,-79.2169174 +M1H,43.773136,-79.2394761 +M1J,43.7447342,-79.2394761 +M1K,43.7279292,-79.2620294 +M1L,43.7111117,-79.2845772 +M1M,43.716316,-79.2394761 +M1N,43.692657,-79.2648481 +M1P,43.7574096,-79.273304 +M1R,43.7500715,-79.2958491 +M1S,43.7942003,-79.2620294 +M1T,43.7816375,-79.3043021 +M1V,43.8152522,-79.2845772 +M1W,43.7995252,-79.3183887 +M1X,43.8361247,-79.2056361 +M2H,43.8037622,-79.3634517 +M2J,43.7785175,-79.3465557 +M2K,43.7869473,-79.385975 +M2L,43.7574902,-79.3747141 +M2M,43.789053,-79.4084928 +M2N,43.7701199,-79.4084928 +M2P,43.7527583,-79.4000493 +M2R,43.7827364,-79.4422593 +M3A,43.7532586,-79.3296565 +M3B,43.7459058,-79.352188 +M3C,43.7258997,-79.340923 +M3H,43.7543283,-79.4422593 +M3J,43.7679803,-79.4872619 +M3K,43.7374732,-79.4647633 +M3L,43.7390146,-79.5069436 +M3M,43.7284964,-79.4956974 +M3N,43.7616313,-79.5209994 +M4A,43.7258823,-79.3155716 +M4B,43.7063972,-79.309937 +M4C,43.6953439,-79.3183887 +M4E,43.6763574,-79.2930312 +M4G,43.7090604,-79.3634517 +M4H,43.7053689,-79.3493719 +M4J,43.685347,-79.3381065 +M4K,43.6795571,-79.352188 +M4L,43.6689985,-79.3155716 +M4M,43.6595255,-79.340923 +M4N,43.7280205,-79.3887901 +M4P,43.7127511,-79.3901975 +M4R,43.7153834,-79.4056784 +M4S,43.7043244,-79.3887901 +M4T,43.6895743,-79.3831599 +M4V,43.6864123,-79.4000493 +M4W,43.6795626,-79.3775294 +M4X,43.667967,-79.3676753 +M4Y,43.6658599,-79.3831599 +M5A,43.6542599,-79.3606359 +M5B,43.6571618,-79.3789371 +M5C,43.6514939,-79.3754179 +M5E,43.6447708,-79.3733064 +M5G,43.6579524,-79.3873826 +M5H,43.6505712,-79.3845675 +M5J,43.6408157,-79.3817523 +M5K,43.6471768,-79.3815764 +M5L,43.6481985,-79.3798169 +M5M,43.7332825,-79.4197497 +M5N,43.7116948,-79.4169356 +M5P,43.6969476,-79.4113072 +M5R,43.6727097,-79.4056784 +M5S,43.6626956,-79.4000493 +M5T,43.6532057,-79.4000493 +M5V,43.6289467,-79.3944199 +M5W,43.6464352,-79.374846 +M5X,43.6484292,-79.3822802 +M6A,43.718518,-79.4647633 +M6B,43.709577,-79.4450726 +M6C,43.6937813,-79.4281914 +M6E,43.6890256,-79.453512 +M6G,43.669542,-79.4225637 +M6H,43.6690051,-79.4422593 +M6J,43.6479267,-79.4197497 +M6K,43.6368472,-79.4281914 +M6L,43.7137562,-79.4900738 +M6M,43.6911158,-79.4760133 +M6N,43.6731853,-79.4872619 +M6P,43.6616083,-79.4647633 +M6R,43.6489597,-79.456325 +M6S,43.6515706,-79.4844499 +M7A,43.6623015,-79.3894938 +M7R,43.6369656,-79.615819 +M7Y,43.6627439,-79.321558 +M8V,43.6056466,-79.5013207 +M8W,43.6024137,-79.5434841 +M8X,43.6536536,-79.5069436 +M8Y,43.6362579,-79.4985091 +M8Z,43.6288408,-79.5209994 +M9A,43.6678556,-79.5322424 +M9B,43.6509432,-79.5547244 +M9C,43.6435152,-79.5772008 +M9L,43.7563033,-79.5659633 +M9M,43.7247659,-79.5322424 +M9N,43.706876,-79.5181884 +M9P,43.696319,-79.5322424 +M9R,43.6889054,-79.5547244 +M9V,43.7394164,-79.5884369 +M9W,43.7067483,-79.5940544 \ No newline at end of file diff --git a/TorontoNeighborhoods.csv b/TorontoNeighborhoods.csv new file mode 100644 index 0000000..a09ab59 --- /dev/null +++ b/TorontoNeighborhoods.csv @@ -0,0 +1,104 @@ +PostalCode,Brough,Neighborhood +M3A,North York,Parkwoods +M4A,North York,Victoria Village +M5A,Downtown Toronto,"Regent Park,Harbourfront" +M6A,North York,"Lawrence Manor,Lawrence Heights" +M7A,Queen's Park,Ontario Provincial Government +M9A,Etobicoke,Islington Avenue +M1B,Scarborough,"Malvern,Rouge" +M3B,North York,"Don Mills,North" +M4B,East York,"Parkview Hill,Woodbine Gardens" +M5B,Downtown Toronto,"Garden District, Ryerson" +M6B,North York,Glencairn +M9B,Etobicoke,"West Deane Park,Princess Gardens,Martin Grove,Islington,Cloverdale" +M1C,Scarborough,"Rouge Hill,Port Union,Highland Creek" +M3C,North York,"Don Mills,South" +M4C,East York,Woodbine Heights +M5C,Downtown Toronto,St. James Town +M6C,York,Humewood-Cedarvale +M9C,Etobicoke,"Eringate,Bloordale Gardens,Old Burnhamthorpe,Markland Wood" +M1E,Scarborough,"Guildwood,Morningside,West Hill" +M4E,East Toronto,The Beaches +M5E,Downtown Toronto,Berczy Park +M6E,York,Caledonia-Fairbanks +M1G,Scarborough,Woburn +M4G,East York,Leaside +M5G,Downtown Toronto,Central Bay Street +M6G,Downtown Toronto,Christie +M1H,Scarborough,Cedarbrae +M2H,North York,Hillcrest Village +M3H,North York,"Bathurst Manor,Wilson Heights,Downsview North" +M4H,East York,Thorncliffe Park +M5H,Downtown Toronto,"Richmond,Adelaide,King" +M6H,West Toronto,"Dufferin,Dovercourt Village" +M1J,Scarborough,Scarborough Village +M2J,North York,"Fairview,Henry Farm,Oriole" +M3J,North York,"Northwood Park,York University" +M4J,East York/East Toronto,The Danforth East +M5J,Downtown Toronto,"Harbourfront East,Union Station,Toronto Islands" +M6J,West Toronto,"Little Portugal,Trinity" +M1K,Scarborough,"Kennedy Park,Ionview,East Birchmount Park" +M2K,North York,Bayview Village +M3K,North York,"Downsview,East" +M4K,East Toronto,"The Danforth West,Riverdale" +M5K,Downtown Toronto,"Toronto Dominion Centre,Design Exchange" +M6K,West Toronto,"Brockton,Parkdale Village,Exhibition Place" +M1L,Scarborough,"Golden Mile,Clairlea,Oakridge" +M2L,North York,"York Mills,Silver Hills" +M3L,North York,"Downsview,West" +M4L,East Toronto,"India Bazaar,The Beaches West" +M5L,Downtown Toronto,"Commerce Court,Victoria Hotel" +M6L,North York,"North Park,Maple Leaf Park,Upwood Park" +M9L,North York,Humber Summit +M1M,Scarborough,"Cliffside,Cliffcrest,Scarborough Village West" +M2M,North York,"Willowdale,Newtonbrook" +M3M,North York,"Downsview,Central" +M4M,East Toronto,Studio District +M5M,North York,"Bedford Park,Lawrence Manor East" +M6M,York,"Del Ray,Mount Dennis,Keelsdale and Silverthorn" +M9M,North York,"Humberlea,Emery" +M1N,Scarborough,"Birch Cliff,Cliffside West" +M2N,North York,"Willowdale,South" +M3N,North York,"Downsview,Northwest" +M4N,Central Toronto,Lawrence Park +M5N,Central Toronto,Roselawn +M6N,York,"Runnymede,The Junction North" +M9N,York,Weston +M1P,Scarborough,"Dorset Park,Wexford Heights,Scarborough Town Centre" +M2P,North York,York Mills West +M4P,Central Toronto,Davisville North +M5P,Central Toronto,Forest Hill North & West +M6P,West Toronto,"High Park,The Junction South" +M9P,Etobicoke,Westmount +M1R,Scarborough,"Wexford,Maryvale" +M2R,North York,"Willowdale,West" +M4R,Central Toronto,North Toronto West +M5R,Central Toronto,"The Annex,North Midtown,Yorkville" +M6R,West Toronto,"Parkdale,Roncesvalles" +M7R,Mississauga,Enclave of L4W +M9R,Etobicoke,"Kingsview Village,St. Phillips,Martin Grove Gardens,Richview Gardens" +M1S,Scarborough,"Agincourt," +M4S,Central Toronto,Davisville +M5S,Downtown Toronto,"University of Toronto,Harbord" +M6S,West Toronto,"Runnymede,Swansea" +M1T,Scarborough,"Clarks Corners,Tam O'Shanter,Sullivan" +M4T,Central Toronto,"Moore Park,Summerhill East" +M5T,Downtown Toronto,"Kensington Market,Chinatown,Grange Park" +M1V,Scarborough,"Milliken,Agincourt North,Steeles East,L'Amoreaux East" +M4V,Central Toronto,"Summerhill West,Rathnelly,South Hill,Forest Hill SE,Deer Park" +M5V,Downtown Toronto,"CN Tower,King and Spadina,Railway Lands,Harbourfront West,Bathurst Quay,South Niagara,Island airport" +M8V,Etobicoke,"New Toronto,Mimico South,Humber Bay Shores" +M9V,Etobicoke,"South Steeles,Silverstone,Humbergate,Jamestown,Mount Olive,Beaumond Heights,Thistletown,Albion Gardens" +M1W,Scarborough,"Steeles West,L'Amoreaux West" +M4W,Downtown Toronto,Rosedale +M5W,Downtown Toronto Stn A,Enclave of M5E +M8W,Etobicoke,"Alderwood,Long Branch" +M9W,Etobicoke Northwest,"Clairville,Humberwood,Woodbine Downs,West Humber,Kipling Heights,Rexdale,Elms,Tandridge,Old Rexdale" +M1X,Scarborough,Upper Rouge +M4X,Downtown Toronto,"St. James Town,Cabbagetown" +M5X,Downtown Toronto,"First Canadian Place,Underground city" +M8X,Etobicoke,"The Kingsway,Montgomery Road,Old Mill North" +M4Y,Downtown Toronto,Church and Wellesley +M7Y,East Toronto Business,Enclave of M4L +M8Y,Etobicoke,"Old Mill South,King's Mill Park,Sunnylea,Humber Bay,Mimico NE,The Queensway East,Royal York South East,Kingsway Park South East" +M8Z,Etobicoke,"Mimico NW,The Queensway West,South of Bloor,Kingsway Park South West,Royal York South West" diff --git a/capstone.ipynb b/capstone.ipynb index a62c8b3..241d0f1 100644 --- a/capstone.ipynb +++ b/capstone.ipynb @@ -10,12 +10,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.5" + "version": "3.9.6" }, "orig_nbformat": 4, "kernelspec": { "name": "python3", - "display_name": "Python 3.9.5 64-bit ('venv': venv)" + "display_name": "Python 3.9.6 64-bit ('venv': venv)" }, "interpreter": { "hash": "b429883b58fb923b9977c99be3a8a6af2533b7bec5e443525bd6c8be5836c39a" @@ -34,30 +34,653 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "# import packages\n", - "import pandas as pd \n", - "import numpy as np " + "import pandas as pd\n", + "import numpy as np \n", + "from bs4 import BeautifulSoup\n", + "import requests\n", + "import geocoder\n", + "from sklearn.cluster import KMeans\n", + "import folium\n", + "import matplotlib.cm as cm\n", + "import matplotlib.colors as colors" ] }, + { + "source": [ + "

Section 01: Web Scrapping

\n", + "

In this section, neighborhood details of Toronto are extracted from a Wikipedia page and stored in pandas dataframe .
\n", + "Further, for future references extracted details are stored in a CSV file.
\n", + "For more details please refer the comments.\n", + "

" + ], + "cell_type": "markdown", + "metadata": {} + }, { "cell_type": "code", "execution_count": 2, "metadata": {}, + "outputs": [], + "source": [ + "# url to the target Wikipedia page\n", + "url = \"https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M\"\n", + "# get html document\n", + "page = requests.get(url)\n", + "# parsing html document to BeautifulSoup\n", + "soup = BeautifulSoup(page.content, 'html.parser')\n", + "# extracting tables\n", + "tables = soup.find_all('table')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# save the table with postal codes as a list\n", + "nbTable = tables[0].text.splitlines()\n", + "# define list to store all rows\n", + "neighborhoods = []\n", + "# looping row by row to extract necessary values\n", + "for row in nbTable:\n", + " if row != '' and 'Not assigned' not in row:\n", + " # define dict to store the values\n", + " cell = {}\n", + " # extracting values\n", + " neighborhood = row.split('(')[1].strip(')')\n", + " neighborhood = neighborhood.replace(' / ', ',').replace(')', ',').strip(' ')\n", + "\n", + " # storing values inside dict\n", + " cell['PostalCode'] = row[0:3]\n", + " cell['Brough'] = row[3:].split('(')[0]\n", + " cell['Neighborhood'] = neighborhood\n", + "\n", + " # appending dict to the list\n", + " neighborhoods.append(cell)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "# transform the extracted values to a DF\n", + "neighborhoods = pd.DataFrame(neighborhoods)\n", + "neighborhoods['Brough'] = neighborhoods['Brough'].replace({'Downtown TorontoStn A PO Boxes25 The Esplanade':'Downtown Toronto Stn A',\n", + " 'East TorontoBusiness reply mail Processing Centre969 Eastern':'East Toronto Business',\n", + " 'EtobicokeNorthwest':'Etobicoke Northwest','East YorkEast Toronto':'East York/East Toronto',\n", + " 'MississaugaCanada Post Gateway Processing Centre':'Mississauga'})" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "# export dataframe as a csv\n", + "neighborhoods.to_csv('TorontoNeighborhoods.csv', index=False)" + ] + }, + { + "source": [ + "

Section 02: Location Update

\n", + "

In this section, previously created dataframe is updated with location details (latitude and longitude of each location).
\n", + "For further details please refer the comments.\n", + "

" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, "outputs": [ { - "output_type": "stream", - "name": "stdout", - "text": [ - "Hello Capstone Project Course!\n" + "output_type": "error", + "ename": "KeyboardInterrupt", + "evalue": "", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mwhile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlocation\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;31m# extracting location data\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mgeoData\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgeocoder\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgoogle\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maddress\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[0mlocation\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgeoData\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlatlng\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[1;31m# loop counter\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\api.py\u001b[0m in \u001b[0;36mgoogle\u001b[1;34m(location, **kwargs)\u001b[0m\n\u001b[0;32m 230\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0melevation\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 231\u001b[0m \"\"\"\n\u001b[1;32m--> 232\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlocation\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mprovider\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'google'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 233\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 234\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\api.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(location, **kwargs)\u001b[0m\n\u001b[0;32m 196\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mmethod\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mprovider\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 197\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid method\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 198\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mprovider\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlocation\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 199\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 200\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\base.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, location, **kwargs)\u001b[0m\n\u001b[0;32m 408\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 409\u001b[0m \u001b[1;31m# query and parse results\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 410\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_initialize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 411\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 412\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__getitem__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\base.py\u001b[0m in \u001b[0;36m_initialize\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 455\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_initialize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 456\u001b[0m \u001b[1;31m# query URL and get valid JSON (also stored in self.json)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 457\u001b[1;33m \u001b[0mjson_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_connect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 458\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 459\u001b[0m \u001b[1;31m# catch errors\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\base.py\u001b[0m in \u001b[0;36m_connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 477\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 478\u001b[0m \u001b[1;31m# make request and get response\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 479\u001b[1;33m self.response = response = self.rate_limited_get(\n\u001b[0m\u001b[0;32m 480\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 481\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\google.py\u001b[0m in \u001b[0;36mrate_limited_get\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 267\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrate_limited_get_for_work\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 268\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 269\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrate_limited_get_for_dev\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 270\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 271\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mratelim\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgreedy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2500\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m60\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;36m60\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;36m24\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\decorator.py\u001b[0m in \u001b[0;36mfun\u001b[1;34m(*args, **kw)\u001b[0m\n\u001b[0;32m 230\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mkwsyntax\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 231\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkw\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfix\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkw\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msig\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 232\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mcaller\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mextras\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 233\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 234\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__doc__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__doc__\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\ratelim\\__init__.py\u001b[0m in \u001b[0;36mwrapped_f\u001b[1;34m(self, f, *args, **kwargs)\u001b[0m\n\u001b[0;32m 36\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 37\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__numcalls\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 38\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 39\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 40\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__call__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\decorator.py\u001b[0m in \u001b[0;36mfun\u001b[1;34m(*args, **kw)\u001b[0m\n\u001b[0;32m 230\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mkwsyntax\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 231\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkw\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfix\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkw\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msig\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 232\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mcaller\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mextras\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 233\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 234\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__doc__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__doc__\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\ratelim\\__init__.py\u001b[0m in \u001b[0;36mwrapped_f\u001b[1;34m(self, f, *args, **kwargs)\u001b[0m\n\u001b[0;32m 36\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 37\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__numcalls\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 38\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 39\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 40\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__call__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\google.py\u001b[0m in \u001b[0;36mrate_limited_get_for_dev\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 272\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mratelim\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgreedy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 273\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mrate_limited_get_for_dev\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 274\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mGoogleQuery\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrate_limited_get\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 275\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 276\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mratelim\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgreedy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m100000\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m60\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;36m60\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;36m24\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Google for Work daily limit\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\geocoder\\base.py\u001b[0m in \u001b[0;36mrate_limited_get\u001b[1;34m(self, url, **kwargs)\u001b[0m\n\u001b[0;32m 508\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mrate_limited_get\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 509\u001b[0m \u001b[1;34m\"\"\" By default, simply wraps a session.get request\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 510\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msession\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 511\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 512\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_adapt_results\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mjson_response\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(self, url, **kwargs)\u001b[0m\n\u001b[0;32m 553\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 554\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefault\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'allow_redirects'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 555\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'GET'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 556\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 557\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m 540\u001b[0m }\n\u001b[0;32m 541\u001b[0m \u001b[0msend_kwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msettings\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 542\u001b[1;33m \u001b[0mresp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0msend_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 543\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 544\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresp\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m 653\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 654\u001b[0m \u001b[1;31m# Send the request\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 655\u001b[1;33m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0madapter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 656\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 657\u001b[0m \u001b[1;31m# Total elapsed time of the request (approximately)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m 437\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 438\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mchunked\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 439\u001b[1;33m resp = conn.urlopen(\n\u001b[0m\u001b[0;32m 440\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 441\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m 697\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 698\u001b[0m \u001b[1;31m# Make the request on the httplib connection object.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 699\u001b[1;33m httplib_response = self._make_request(\n\u001b[0m\u001b[0;32m 700\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 701\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m 443\u001b[0m \u001b[1;31m# Python 3 (including for exceptions like SystemExit).\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 444\u001b[0m \u001b[1;31m# Otherwise it looks like a bug in the code.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 445\u001b[1;33m \u001b[0msix\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraise_from\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 446\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mSocketTimeout\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mBaseSSLError\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mSocketError\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 447\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_raise_timeout\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0merr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimeout_value\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mread_timeout\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\urllib3\\packages\\six.py\u001b[0m in \u001b[0;36mraise_from\u001b[1;34m(value, from_value)\u001b[0m\n", + "\u001b[1;32mc:\\Users\\ROG\\Documents\\coding\\python\\venv\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m 438\u001b[0m \u001b[1;31m# Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 439\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 440\u001b[1;33m \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 441\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mBaseException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 442\u001b[0m \u001b[1;31m# Remove the TypeError from the exception chain in\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\Python39\\lib\\http\\client.py\u001b[0m in \u001b[0;36mgetresponse\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1347\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1348\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1349\u001b[1;33m \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbegin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1350\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mConnectionError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1351\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\Python39\\lib\\http\\client.py\u001b[0m in \u001b[0;36mbegin\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 314\u001b[0m \u001b[1;31m# read until we get a non-100 response\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 315\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 316\u001b[1;33m \u001b[0mversion\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatus\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreason\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 317\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mstatus\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mCONTINUE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 318\u001b[0m \u001b[1;32mbreak\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\Python39\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_read_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 275\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 276\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 277\u001b[1;33m \u001b[0mline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_MAXLINE\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"iso-8859-1\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 278\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mline\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0m_MAXLINE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 279\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mLineTooLong\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"status line\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\Python39\\lib\\socket.py\u001b[0m in \u001b[0;36mreadinto\u001b[1;34m(self, b)\u001b[0m\n\u001b[0;32m 702\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 703\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 704\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 705\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 706\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_timeout_occurred\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\Python39\\lib\\ssl.py\u001b[0m in \u001b[0;36mrecv_into\u001b[1;34m(self, buffer, nbytes, flags)\u001b[0m\n\u001b[0;32m 1239\u001b[0m \u001b[1;34m\"non-zero flags not allowed in calls to recv_into() on %s\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1240\u001b[0m self.__class__)\n\u001b[1;32m-> 1241\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnbytes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuffer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1242\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1243\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbuffer\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnbytes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mflags\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mC:\\Python39\\lib\\ssl.py\u001b[0m in \u001b[0;36mread\u001b[1;34m(self, len, buffer)\u001b[0m\n\u001b[0;32m 1097\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1098\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mbuffer\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1099\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuffer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1100\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1101\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ - "print(\"Hello Capstone Project Course!\")" + "# initialize variable\n", + "locations = []\n", + "# loop until get the data\n", + "for index, row in neighborhoods.iterrows():\n", + " location = None\n", + " cell = {}\n", + " address = \"{}, {}\".format(row['PostalCode'], row['Brough'])\n", + " # introduce a loop limiter\n", + " i = 0\n", + " while(location is None):\n", + " # extracting location data\n", + " geoData = geocoder.google(address)\n", + " location = geoData.latlng\n", + " # loop counter\n", + " i = i+1\n", + " if i>5:\n", + " break\n", + " # appending values to the dict\n", + " cell['PostalCode'] = row['PostalCode']\n", + " cell['Brough'] = row['Brough']\n", + " cell['Neighborhood'] = row['Neighborhood']\n", + " if location != None:\n", + " cell['Latitude'] = location[0]\n", + " call['Longitude'] = location[1]\n", + " else:\n", + " cell['Latitude'] = None\n", + " cell['Longitude'] = None\n", + " \n", + " # append dict to the list\n", + " locations.append(cell)" + ] + }, + { + "source": [ + "

I tried to extract latitudes and longitudes of all locations with above function. But no luck.
\n", + "So, I move on and use the provided csv file

" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " Postal Code Latitude Longitude\n", + "0 M1B 43.806686 -79.194353\n", + "1 M1C 43.784535 -79.160497\n", + "2 M1E 43.763573 -79.188711\n", + "3 M1G 43.770992 -79.216917\n", + "4 M1H 43.773136 -79.239476" + ], + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Postal CodeLatitudeLongitude
0M1B43.806686-79.194353
1M1C43.784535-79.160497
2M1E43.763573-79.188711
3M1G43.770992-79.216917
4M1H43.773136-79.239476
\n
" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "# read the csv file to a df\n", + "geoSpatialData = pd.read_csv(\"Geospatial_Coordinates.csv\")\n", + "geoSpatialData.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# rename column to merge two dfs\n", + "geoSpatialData.rename(columns={'Postal Code':'PostalCode'}, inplace=True)\n", + "# merge two dfs\n", + "df = pd.merge(neighborhoods, geoSpatialData, on='PostalCode')" + ] + }, + { + "source": [ + "

Section 03: Clustering

\n", + "

In this section neighberhoods are clustered using k-mean method.
\n", + "For further details please refer the comments.

" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " PostalCode Brough Neighborhood Latitude Longitude\n", + "0 M5A Downtown Toronto Regent Park,Harbourfront 43.654260 -79.360636\n", + "1 M5B Downtown Toronto Garden District, Ryerson 43.657162 -79.378937\n", + "2 M5C Downtown Toronto St. James Town 43.651494 -79.375418\n", + "3 M4E East Toronto The Beaches 43.676357 -79.293031\n", + "4 M5E Downtown Toronto Berczy Park 43.644771 -79.373306" + ], + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PostalCodeBroughNeighborhoodLatitudeLongitude
0M5ADowntown TorontoRegent Park,Harbourfront43.654260-79.360636
1M5BDowntown TorontoGarden District, Ryerson43.657162-79.378937
2M5CDowntown TorontoSt. James Town43.651494-79.375418
3M4EEast TorontoThe Beaches43.676357-79.293031
4M5EDowntown TorontoBerczy Park43.644771-79.373306
\n
" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "# extracting neighborhoods in Toronto\n", + "toronto = df[df['Brough'].str.contains('Toronto')].reset_index(drop=True)\n", + "toronto.head()" + ] + }, + { + "source": [ + "

I tried to get location of Toronto using geocoder. But no sucess.
\n", + "So, I use the first location from dataframe to create a map.

" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# extracting latitudes and longitudes of first row in DF\n", + "latitudeToronto = toronto.loc[0, 'Latitude']\n", + "longitudeToronto = toronto.loc[0, 'Longitude']" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "text/html": "

Make this Notebook Trusted to load map: File -> Trust Notebook
" + }, + "metadata": {}, + "execution_count": 11 + } + ], + "source": [ + "# create a map object\n", + "mapToronto = folium.Map(location=[latitudeToronto, longitudeToronto], zoom_start=12)\n", + "\n", + "# add markers to map\n", + "for latitude, longitude, label in zip(toronto['Latitude'], toronto['Longitude'], toronto['Neighborhood']):\n", + " label = folium.Popup(label, parse_html=True)\n", + " folium.CircleMarker(\n", + " [latitude, longitude],\n", + " radius=5,\n", + " popup=label,\n", + " color='blue',\n", + " fill=True,\n", + " fill_color='blue',\n", + " fill_opacity=0.7,\n", + " parse_html=True\n", + " ).add_to(mapToronto)\n", + "\n", + "# show the map\n", + "mapToronto" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "# Foursqure credentials\n", + "CLIENT_ID = 'AZ00BPKDRUC3GAPGW3O5Z01VNQV4UWDU44WO1ZW4ZZ4YTA2P' # Foursquare ID\n", + "CLIENT_SECRET = 'EMQ4TLHUPGCXYWPXB53LCW1GPGLIRA5QFDU4HH5F3TXTACBE' # Foursquare Secret\n", + "VERSION = '20180605' # Foursquare API version\n", + "LIMIT = 100 # A default Foursquare API limit value" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "# get nearby venues of each brough\n", + "# define a list to store venues\n", + "venues = []\n", + "# loop through the DF to get venue details\n", + "for latitude, longitude, neighborhood in zip(toronto['Latitude'], toronto['Longitude'], toronto['Neighborhood']):\n", + " # request url\n", + " url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(\n", + " CLIENT_ID, \n", + " CLIENT_SECRET, \n", + " VERSION, \n", + " latitude, \n", + " longitude, \n", + " 500, \n", + " LIMIT)\n", + " # make a get request\n", + " results = requests.get(url).json()['response']['groups'][0]['items']\n", + " # appending venue details to list\n", + " venues.append([(\n", + " neighborhood,\n", + " latitude,\n", + " longitude,\n", + " venue['venue']['name'],\n", + " venue['venue']['location']['lat'],\n", + " venue['venue']['location']['lng'],\n", + " venue['venue']['categories'][0]['name']) for venue in results])" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " Neighborhood Neighborhood Latitude Neighborhood Longitude \\\n", + "0 Regent Park,Harbourfront 43.65426 -79.360636 \n", + "1 Regent Park,Harbourfront 43.65426 -79.360636 \n", + "2 Regent Park,Harbourfront 43.65426 -79.360636 \n", + "3 Regent Park,Harbourfront 43.65426 -79.360636 \n", + "4 Regent Park,Harbourfront 43.65426 -79.360636 \n", + "\n", + " Venue Venue Latiitude Venue Longitude \\\n", + "0 Tandem Coffee 43.653559 -79.361809 \n", + "1 Roselle Desserts 43.653447 -79.362017 \n", + "2 Cooper Koo Family YMCA 43.653249 -79.358008 \n", + "3 Body Blitz Spa East 43.654735 -79.359874 \n", + "4 Impact Kitchen 43.656369 -79.356980 \n", + "\n", + " Venue Category \n", + "0 Coffee Shop \n", + "1 Bakery \n", + "2 Distribution Center \n", + "3 Spa \n", + "4 Restaurant " + ], + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
NeighborhoodNeighborhood LatitudeNeighborhood LongitudeVenueVenue LatiitudeVenue LongitudeVenue Category
0Regent Park,Harbourfront43.65426-79.360636Tandem Coffee43.653559-79.361809Coffee Shop
1Regent Park,Harbourfront43.65426-79.360636Roselle Desserts43.653447-79.362017Bakery
2Regent Park,Harbourfront43.65426-79.360636Cooper Koo Family YMCA43.653249-79.358008Distribution Center
3Regent Park,Harbourfront43.65426-79.360636Body Blitz Spa East43.654735-79.359874Spa
4Regent Park,Harbourfront43.65426-79.360636Impact Kitchen43.656369-79.356980Restaurant
\n
" + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "# converting venue list to DF\n", + "nearbyVenues = pd.DataFrame([item for venue in venues for item in venue])\n", + "nearbyVenues.columns = ['Neighborhood',\n", + " 'Neighborhood Latitude',\n", + " 'Neighborhood Longitude',\n", + " 'Venue',\n", + " 'Venue Latiitude',\n", + " 'Venue Longitude',\n", + " 'Venue Category']\n", + "nearbyVenues.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "# one hot encoding\n", + "torontoOneHot = pd.get_dummies(nearbyVenues[['Venue Category']], prefix=\"\", prefix_sep=\"\")\n", + "# add neighborhood column to the DF\n", + "torontoOneHot['Neighborhood'] = nearbyVenues['Neighborhood']\n", + "# rearranging columns\n", + "columnNames = ['Neighborhood'] + [columnName for columnName in list(torontoOneHot.columns) if columnName!='Neighborhood']\n", + "torontoOneHot = torontoOneHot[columnNames]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "# create grouped DF\n", + "torontoGrouped = torontoOneHot.groupby('Neighborhood').mean()\n", + "torontoGrouped.reset_index(inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "# define a function to get most common venues\n", + "def getMostCommonVenues(row, topVenueCount):\n", + " categories = row.iloc[1:]\n", + " categoriesSorted = categories.sort_values(ascending=False)\n", + " return categoriesSorted.index[0:topVenueCount]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "# select top venue count\n", + "numTopVenues = 10\n", + "indicators = [\"st\", \"nd\", \"rd\"]\n", + "\n", + "# create a list of column names\n", + "columnNames = ['Neighborhood']\n", + "for i in range(numTopVenues):\n", + " if i\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Neighborhood1st Most Common Venue2nd Most Common Venue3rd Most Common Venue4th Most Common Venue5th Most Common Venue6th Most Common Venue7th Most Common Venue8th Most Common Venue9th Most Common Venue10th Most Common Venue
0Berczy ParkCoffee ShopCocktail BarBakeryFarmers MarketBeer BarItalian RestaurantCheese ShopSeafood RestaurantRestaurantPub
1Brockton,Parkdale Village,Exhibition PlaceCaféBreakfast SpotCoffee ShopItalian RestaurantPerforming Arts VenueConvenience StoreNightclubMusic VenueRestaurantClimbing Gym
2CN Tower,King and Spadina,Railway Lands,Harbou...Airport ServiceAirport TerminalAirportBoat or FerrySculpture GardenRental Car LocationPlaneAirport Food CourtCoffee ShopHarbor / Marina
3Central Bay StreetCoffee ShopCaféSandwich PlaceItalian RestaurantBubble Tea ShopRestaurantBurger JointSalad PlaceRamen RestaurantDonut Shop
4ChristieGrocery StoreCaféParkItalian RestaurantRestaurantCandy StoreAthletics & SportsCoffee ShopNightclubBaby Store
\n" + }, + "metadata": {}, + "execution_count": 60 + } + ], + "source": [ + "# create a DF with new column names\n", + "sortedNeighborhoodVenues = pd.DataFrame(columns=columnNames)\n", + "sortedNeighborhoodVenues['Neighborhood'] = torontoGrouped['Neighborhood']\n", + "# filling values to DF using getMostCommonVenues function\n", + "for i in range(torontoGrouped.shape[0]):\n", + " sortedNeighborhoodVenues.iloc[i, 1:] = getMostCommonVenues(torontoGrouped.iloc[i, :], numTopVenues)\n", + "sortedNeighborhoodVenues.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [], + "source": [ + "# clustering neighborhoods\n", + "# number of clusters\n", + "kClusters = 7\n", + "# removing labels from DF\n", + "torontoGroupedClustering = torontoGrouped.drop('Neighborhood', 1)\n", + "# cluster the dataset using KMeans\n", + "kMeans = KMeans(kClusters, random_state=0).fit(torontoGroupedClustering)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " PostalCode Brough Neighborhood Latitude \\\n", + "0 M5A Downtown Toronto Regent Park,Harbourfront 43.654260 \n", + "1 M5B Downtown Toronto Garden District, Ryerson 43.657162 \n", + "2 M5C Downtown Toronto St. James Town 43.651494 \n", + "3 M4E East Toronto The Beaches 43.676357 \n", + "4 M5E Downtown Toronto Berczy Park 43.644771 \n", + "\n", + " Longitude Cluster Labels 1st Most Common Venue 2nd Most Common Venue \\\n", + "0 -79.360636 2 Coffee Shop Pub \n", + "1 -79.378937 2 Coffee Shop Clothing Store \n", + "2 -79.375418 2 Café Coffee Shop \n", + "3 -79.293031 6 Health Food Store Trail \n", + "4 -79.373306 2 Coffee Shop Cocktail Bar \n", + "\n", + " 3rd Most Common Venue 4th Most Common Venue 5th Most Common Venue \\\n", + "0 Bakery Park Café \n", + "1 Sandwich Place Café Italian Restaurant \n", + "2 Cocktail Bar Beer Bar Restaurant \n", + "3 Pub Asian Restaurant Monument / Landmark \n", + "4 Bakery Farmers Market Beer Bar \n", + "\n", + " 6th Most Common Venue 7th Most Common Venue 8th Most Common Venue \\\n", + "0 Theater Breakfast Spot Event Space \n", + "1 Middle Eastern Restaurant Japanese Restaurant Cosmetics Shop \n", + "2 Creperie Gastropub Lingerie Store \n", + "3 Malay Restaurant Market Martial Arts School \n", + "4 Italian Restaurant Cheese Shop Seafood Restaurant \n", + "\n", + " 9th Most Common Venue 10th Most Common Venue \n", + "0 Farmers Market Restaurant \n", + "1 Hotel Pizza Place \n", + "2 Seafood Restaurant Moroccan Restaurant \n", + "3 Massage Studio Mediterranean Restaurant \n", + "4 Restaurant Pub " + ], + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PostalCodeBroughNeighborhoodLatitudeLongitudeCluster Labels1st Most Common Venue2nd Most Common Venue3rd Most Common Venue4th Most Common Venue5th Most Common Venue6th Most Common Venue7th Most Common Venue8th Most Common Venue9th Most Common Venue10th Most Common Venue
0M5ADowntown TorontoRegent Park,Harbourfront43.654260-79.3606362Coffee ShopPubBakeryParkCaféTheaterBreakfast SpotEvent SpaceFarmers MarketRestaurant
1M5BDowntown TorontoGarden District, Ryerson43.657162-79.3789372Coffee ShopClothing StoreSandwich PlaceCaféItalian RestaurantMiddle Eastern RestaurantJapanese RestaurantCosmetics ShopHotelPizza Place
2M5CDowntown TorontoSt. James Town43.651494-79.3754182CaféCoffee ShopCocktail BarBeer BarRestaurantCreperieGastropubLingerie StoreSeafood RestaurantMoroccan Restaurant
3M4EEast TorontoThe Beaches43.676357-79.2930316Health Food StoreTrailPubAsian RestaurantMonument / LandmarkMalay RestaurantMarketMartial Arts SchoolMassage StudioMediterranean Restaurant
4M5EDowntown TorontoBerczy Park43.644771-79.3733062Coffee ShopCocktail BarBakeryFarmers MarketBeer BarItalian RestaurantCheese ShopSeafood RestaurantRestaurantPub
\n
" + }, + "metadata": {}, + "execution_count": 62 + } + ], + "source": [ + "# adding cluster labels to DF\n", + "sortedNeighborhoodVenues.insert(0, 'Cluster Labels', kMeans.labels_)\n", + "# creating new DF to murge other DFs\n", + "torontoMerged = toronto\n", + "torontoMerged = torontoMerged.join(sortedNeighborhoodVenues.set_index('Neighborhood'), on='Neighborhood')\n", + "torontoMerged.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ], + "text/html": "
Make this Notebook Trusted to load map: File -> Trust Notebook
" + }, + "metadata": {}, + "execution_count": 63 + } + ], + "source": [ + "# create a map object\n", + "mapTorontoClusters = folium.Map(location=[latitudeToronto, longitudeToronto], zoom_start=12)\n", + "# set colors for different markers\n", + "x = np.arange(kClusters)\n", + "y = [1+x+(1*x)**2 for i in range(kClusters)]\n", + "colorsArray = cm.rainbow(np.linspace(0, 1, len(y)))\n", + "rainbow = [colors.rgb2hex(i) for i in colorsArray]\n", + "# add markers to map\n", + "for latitude, longitude, label, cluster in zip(torontoMerged['Latitude'], \n", + " torontoMerged['Longitude'], \n", + " torontoMerged['Neighborhood'],\n", + " torontoMerged['Cluster Labels']):\n", + " label = folium.Popup(label + 'Cluster' + str(cluster), parse_html=True)\n", + " folium.CircleMarker(\n", + " [latitude, longitude],\n", + " radius=5,\n", + " popup=label,\n", + " color=rainbow[cluster-1],\n", + " fill=True,\n", + " fill_color=rainbow[cluster-1],\n", + " fill_opacity=0.7,\n", + " parse_html=True\n", + " ).add_to(mapTorontoClusters)\n", + "# show map\n", + "mapTorontoClusters" ] }, {