{"cells": [{"metadata": {}, "cell_type": "markdown", "source": " # Segmenting and Clustering of Neighborhoods in Toronto City\n\n As Github does not support folium map, so if you want to see fully rendered notebook, click on this link \n https://nbviewer.jupyter.org/github/Mr-Piyush-Kumar/Data_Science_Projects/blob/master/Toronto_City_Neighborhood_Clustring/TorrontoCityNeighborhoodClustring.ipynb"}, {"metadata": {}, "cell_type": "markdown", "source": "### Introduction\n\nThis Notebook is the part of IBM Data Science Capastone Project. In This project, I am going to explore the nearby venues of Toronto City and after I will use machine learning to create clusters of these neighborhoods and will show all these clusters in the map of Toronto City.\n### Created By:- Piyush Kumar"}, {"metadata": {}, "cell_type": "markdown", "source": "# Part - 1 of this Project"}, {"metadata": {}, "cell_type": "markdown", "source": "### Objective\nDisplaying Toronto City Neighborhoods dataset after scrapping and cleaning from wikipedia a page."}, {"metadata": {}, "cell_type": "code", "source": "# Importing libraries.\nimport pandas as pd\nimport numpy as np", "execution_count": 1, "outputs": []}, {"metadata": {}, "cell_type": "code", "source": "# This line of code will fetch all the tables in this 'https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M' \n# wikipedia page.\n\ntabels = pd.read_html('https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M')", "execution_count": 2, "outputs": []}, {"metadata": {}, "cell_type": "code", "source": "len(tabels)", "execution_count": 3, "outputs": [{"output_type": "execute_result", "execution_count": 3, "data": {"text/plain": "3"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "As we can see there are three tabels. Lets check which table is reqiured for us."}, {"metadata": {}, "cell_type": "code", "source": "# 1st Table, \n# NOTE:- each element in tabels list is a DataFrame.\n\ntabels[0].head()", "execution_count": 4, "outputs": [{"output_type": "execute_result", "execution_count": 4, "data": {"text/plain": " Postcode Borough Neighbourhood\n0 M1A Not assigned Not assigned\n1 M2A Not assigned Not assigned\n2 M3A North York Parkwoods\n3 M4A North York Victoria Village\n4 M5A Downtown Toronto Harbourfront", "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
PostcodeBoroughNeighbourhood
0M1ANot assignedNot assigned
1M2ANot assignedNot assigned
2M3ANorth YorkParkwoods
3M4ANorth YorkVictoria Village
4M5ADowntown TorontoHarbourfront
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "As we can see this is the table which we reqiured, so there is no need to check other tabels."}, {"metadata": {}, "cell_type": "code", "source": "# Storing tabel 1 in a saparate DataFrame.\n\nToronto_df = tabels[0]\ndel(tabels) # deleting tables list, as we don't required it anymore.\nToronto_df.head()", "execution_count": 5, "outputs": [{"output_type": "execute_result", "execution_count": 5, "data": {"text/plain": " Postcode Borough Neighbourhood\n0 M1A Not assigned Not assigned\n1 M2A Not assigned Not assigned\n2 M3A North York Parkwoods\n3 M4A North York Victoria Village\n4 M5A Downtown Toronto Harbourfront", "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
PostcodeBoroughNeighbourhood
0M1ANot assignedNot assigned
1M2ANot assignedNot assigned
2M3ANorth YorkParkwoods
3M4ANorth YorkVictoria Village
4M5ADowntown TorontoHarbourfront
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "# Data Wrangling # Data Preprocessing\n\n# 1- Changing DataFrame's columns name according to project instructions\nToronto_df.columns = ['PostalCode','Borough','Neighborhood']\n\n# 2- Removing those rows whoose Borough is Not assigned\nToronto_df = Toronto_df[Toronto_df['Borough']!='Not assigned']\n\n# 3- Grouping of Postal Code\ntemp_lst = []\nfor name, group in Toronto_df.groupby('PostalCode'):\n temp_lst.append([name, group['Borough'].unique()[0],\", \".join(set(group['Neighborhood'].values))])\nToronto_df = pd.DataFrame(temp_lst, columns = ['PostalCode','Borough','Neighborhood'])\n\n# 4- Replacing Not assigned values in Neighborhood with corresponding Borough\nindex = Toronto_df['Neighborhood'][Toronto_df['Neighborhood'].apply(lambda x: 'Not assigned' in str(x)) == True].index \n # index where neighborhood is Not assigned\n \ncode = Toronto_df.iloc[index]['PostalCode'].values[0] # postal code where neighborhood is Not assigned\nToronto_df['Neighborhood'][Toronto_df['PostalCode']==code] = Toronto_df['Borough'] # replacing \n\nToronto_df", "execution_count": 6, "outputs": [{"output_type": "execute_result", "execution_count": 6, "data": {"text/plain": " PostalCode Borough \\\n0 M1B Scarborough \n1 M1C Scarborough \n2 M1E Scarborough \n3 M1G Scarborough \n4 M1H Scarborough \n5 M1J Scarborough \n6 M1K Scarborough \n7 M1L Scarborough \n8 M1M Scarborough \n9 M1N Scarborough \n10 M1P Scarborough \n11 M1R Scarborough \n12 M1S Scarborough \n13 M1T Scarborough \n14 M1V Scarborough \n15 M1W Scarborough \n16 M1X Scarborough \n17 M2H North York \n18 M2J North York \n19 M2K North York \n20 M2L North York \n21 M2M North York \n22 M2N North York \n23 M2P North York \n24 M2R North York \n25 M3A North York \n26 M3B North York \n27 M3C North York \n28 M3H North York \n29 M3J North York \n.. ... ... \n73 M6C York \n74 M6E York \n75 M6G Downtown Toronto \n76 M6H West Toronto \n77 M6J West Toronto \n78 M6K West Toronto \n79 M6L North York \n80 M6M York \n81 M6N York \n82 M6P West Toronto \n83 M6R West Toronto \n84 M6S West Toronto \n85 M7A Downtown Toronto \n86 M7R Mississauga \n87 M7Y East Toronto \n88 M8V Etobicoke \n89 M8W Etobicoke \n90 M8X Etobicoke \n91 M8Y Etobicoke \n92 M8Z Etobicoke \n93 M9A Queen's Park \n94 M9B Etobicoke \n95 M9C Etobicoke \n96 M9L North York \n97 M9M North York \n98 M9N York \n99 M9P Etobicoke \n100 M9R Etobicoke \n101 M9V Etobicoke \n102 M9W Etobicoke \n\n Neighborhood \n0 Rouge, Malvern \n1 Rouge Hill, Highland Creek, Port Union \n2 Guildwood, Morningside, West Hill \n3 Woburn \n4 Cedarbrae \n5 Scarborough Village \n6 Kennedy Park, East Birchmount Park, Ionview \n7 Oakridge, Clairlea, Golden Mile \n8 Scarborough Village West, Cliffcrest, Cliffside \n9 Cliffside West, Birch Cliff \n10 Dorset Park, Wexford Heights, Scarborough Town... \n11 Wexford, Maryvale \n12 Agincourt \n13 Tam O'Shanter, Clarks Corners, Sullivan \n14 Steeles East, L'Amoreaux East, Milliken, Aginc... \n15 L'Amoreaux West \n16 Upper Rouge \n17 Hillcrest Village \n18 Oriole, Fairview, Henry Farm \n19 Bayview Village \n20 Silver Hills, York Mills \n21 Willowdale, Newtonbrook \n22 Willowdale South \n23 York Mills West \n24 Willowdale West \n25 Parkwoods \n26 Don Mills North \n27 Flemingdon Park, Don Mills South \n28 Downsview North, Wilson Heights, Bathurst Manor \n29 Northwood Park, York University \n.. ... \n73 Humewood-Cedarvale \n74 Caledonia-Fairbanks \n75 Christie \n76 Dovercourt Village, Dufferin \n77 Trinity, Little Portugal \n78 Parkdale Village, Brockton, Exhibition Place \n79 Downsview, North Park, Upwood Park \n80 Silverthorn, Mount Dennis, Keelesdale, Del Ray \n81 The Junction North, Runnymede \n82 The Junction South, High Park \n83 Parkdale, Roncesvalles \n84 Swansea, Runnymede \n85 Queen's Park \n86 Canada Post Gateway Processing Centre \n87 Business Reply Mail Processing Centre 969 Eastern \n88 New Toronto, Mimico South, Humber Bay Shores \n89 Alderwood, Long Branch \n90 The Kingsway, Old Mill North, Montgomery Road \n91 Mimico NE, Royal York South East, Sunnylea, Ki... \n92 Royal York South West, Mimico NW, The Queenswa... \n93 Queen's Park \n94 West Deane Park, Cloverdale, Martin Grove, Pri... \n95 Bloordale Gardens, Old Burnhamthorpe, Eringate... \n96 Humber Summit \n97 Humberlea, Emery \n98 Weston \n99 Westmount \n100 Martin Grove Gardens, Kingsview Village, St. P... \n101 Albion Gardens, Mount Olive, Jamestown, Beaumo... \n102 Northwest \n\n[103 rows x 3 columns]", "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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PostalCodeBoroughNeighborhood
0M1BScarboroughRouge, Malvern
1M1CScarboroughRouge Hill, Highland Creek, Port Union
2M1EScarboroughGuildwood, Morningside, West Hill
3M1GScarboroughWoburn
4M1HScarboroughCedarbrae
5M1JScarboroughScarborough Village
6M1KScarboroughKennedy Park, East Birchmount Park, Ionview
7M1LScarboroughOakridge, Clairlea, Golden Mile
8M1MScarboroughScarborough Village West, Cliffcrest, Cliffside
9M1NScarboroughCliffside West, Birch Cliff
10M1PScarboroughDorset Park, Wexford Heights, Scarborough Town...
11M1RScarboroughWexford, Maryvale
12M1SScarboroughAgincourt
13M1TScarboroughTam O'Shanter, Clarks Corners, Sullivan
14M1VScarboroughSteeles East, L'Amoreaux East, Milliken, Aginc...
15M1WScarboroughL'Amoreaux West
16M1XScarboroughUpper Rouge
17M2HNorth YorkHillcrest Village
18M2JNorth YorkOriole, Fairview, Henry Farm
19M2KNorth YorkBayview Village
20M2LNorth YorkSilver Hills, York Mills
21M2MNorth YorkWillowdale, Newtonbrook
22M2NNorth YorkWillowdale South
23M2PNorth YorkYork Mills West
24M2RNorth YorkWillowdale West
25M3ANorth YorkParkwoods
26M3BNorth YorkDon Mills North
27M3CNorth YorkFlemingdon Park, Don Mills South
28M3HNorth YorkDownsview North, Wilson Heights, Bathurst Manor
29M3JNorth YorkNorthwood Park, York University
............
73M6CYorkHumewood-Cedarvale
74M6EYorkCaledonia-Fairbanks
75M6GDowntown TorontoChristie
76M6HWest TorontoDovercourt Village, Dufferin
77M6JWest TorontoTrinity, Little Portugal
78M6KWest TorontoParkdale Village, Brockton, Exhibition Place
79M6LNorth YorkDownsview, North Park, Upwood Park
80M6MYorkSilverthorn, Mount Dennis, Keelesdale, Del Ray
81M6NYorkThe Junction North, Runnymede
82M6PWest TorontoThe Junction South, High Park
83M6RWest TorontoParkdale, Roncesvalles
84M6SWest TorontoSwansea, Runnymede
85M7ADowntown TorontoQueen's Park
86M7RMississaugaCanada Post Gateway Processing Centre
87M7YEast TorontoBusiness Reply Mail Processing Centre 969 Eastern
88M8VEtobicokeNew Toronto, Mimico South, Humber Bay Shores
89M8WEtobicokeAlderwood, Long Branch
90M8XEtobicokeThe Kingsway, Old Mill North, Montgomery Road
91M8YEtobicokeMimico NE, Royal York South East, Sunnylea, Ki...
92M8ZEtobicokeRoyal York South West, Mimico NW, The Queenswa...
93M9AQueen's ParkQueen's Park
94M9BEtobicokeWest Deane Park, Cloverdale, Martin Grove, Pri...
95M9CEtobicokeBloordale Gardens, Old Burnhamthorpe, Eringate...
96M9LNorth YorkHumber Summit
97M9MNorth YorkHumberlea, Emery
98M9NYorkWeston
99M9PEtobicokeWestmount
100M9REtobicokeMartin Grove Gardens, Kingsview Village, St. P...
101M9VEtobicokeAlbion Gardens, Mount Olive, Jamestown, Beaumo...
102M9WEtobicokeNorthwest
\n

103 rows \u00d7 3 columns

\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "print('No. of rows in Toronto Data Frame are ',Toronto_df.shape[0],'.')", "execution_count": 7, "outputs": [{"output_type": "stream", "text": "No. of rows in Toronto Data Frame are 103 .\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "# Part - 2 of this Project"}, {"metadata": {}, "cell_type": "markdown", "source": "### Objective\nGetting geographical co-ordinates of each neighborhood."}, {"metadata": {}, "cell_type": "code", "source": "coordinates_data = pd.read_csv('http://cocl.us/Geospatial_data') # Downloading coordinates data.\ncoordinates_data.columns = ['PostalCode','Latitude','Longitude']\ncoordinates_data.head()", "execution_count": 8, "outputs": [{"output_type": "execute_result", "execution_count": 8, "data": {"text/plain": " PostalCode Latitude Longitude\n0 M1B 43.806686 -79.194353\n1 M1C 43.784535 -79.160497\n2 M1E 43.763573 -79.188711\n3 M1G 43.770992 -79.216917\n4 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
PostalCodeLatitudeLongitude
0M1B43.806686-79.194353
1M1C43.784535-79.160497
2M1E43.763573-79.188711
3M1G43.770992-79.216917
4M1H43.773136-79.239476
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "# merging Toronto_df and coordinates_data DataFrame together\nToronto_df = Toronto_df.merge(coordinates_data, how='left',on='PostalCode')\nToronto_df", "execution_count": 9, "outputs": [{"output_type": "execute_result", "execution_count": 9, "data": {"text/plain": " PostalCode Borough \\\n0 M1B Scarborough \n1 M1C Scarborough \n2 M1E Scarborough \n3 M1G Scarborough \n4 M1H Scarborough \n5 M1J Scarborough \n6 M1K Scarborough \n7 M1L Scarborough \n8 M1M Scarborough \n9 M1N Scarborough \n10 M1P Scarborough \n11 M1R Scarborough \n12 M1S Scarborough \n13 M1T Scarborough \n14 M1V Scarborough \n15 M1W Scarborough \n16 M1X Scarborough \n17 M2H North York \n18 M2J North York \n19 M2K North York \n20 M2L North York \n21 M2M North York \n22 M2N North York \n23 M2P North York \n24 M2R North York \n25 M3A North York \n26 M3B North York \n27 M3C North York \n28 M3H North York \n29 M3J North York \n.. ... ... \n73 M6C York \n74 M6E York \n75 M6G Downtown Toronto \n76 M6H West Toronto \n77 M6J West Toronto \n78 M6K West Toronto \n79 M6L North York \n80 M6M York \n81 M6N York \n82 M6P West Toronto \n83 M6R West Toronto \n84 M6S West Toronto \n85 M7A Downtown Toronto \n86 M7R Mississauga \n87 M7Y East Toronto \n88 M8V Etobicoke \n89 M8W Etobicoke \n90 M8X Etobicoke \n91 M8Y Etobicoke \n92 M8Z Etobicoke \n93 M9A Queen's Park \n94 M9B Etobicoke \n95 M9C Etobicoke \n96 M9L North York \n97 M9M North York \n98 M9N York \n99 M9P Etobicoke \n100 M9R Etobicoke \n101 M9V Etobicoke \n102 M9W Etobicoke \n\n Neighborhood Latitude Longitude \n0 Rouge, Malvern 43.806686 -79.194353 \n1 Rouge Hill, Highland Creek, Port Union 43.784535 -79.160497 \n2 Guildwood, Morningside, West Hill 43.763573 -79.188711 \n3 Woburn 43.770992 -79.216917 \n4 Cedarbrae 43.773136 -79.239476 \n5 Scarborough Village 43.744734 -79.239476 \n6 Kennedy Park, East Birchmount Park, Ionview 43.727929 -79.262029 \n7 Oakridge, Clairlea, Golden Mile 43.711112 -79.284577 \n8 Scarborough Village West, Cliffcrest, Cliffside 43.716316 -79.239476 \n9 Cliffside West, Birch Cliff 43.692657 -79.264848 \n10 Dorset Park, Wexford Heights, Scarborough Town... 43.757410 -79.273304 \n11 Wexford, Maryvale 43.750072 -79.295849 \n12 Agincourt 43.794200 -79.262029 \n13 Tam O'Shanter, Clarks Corners, Sullivan 43.781638 -79.304302 \n14 Steeles East, L'Amoreaux East, Milliken, Aginc... 43.815252 -79.284577 \n15 L'Amoreaux West 43.799525 -79.318389 \n16 Upper Rouge 43.836125 -79.205636 \n17 Hillcrest Village 43.803762 -79.363452 \n18 Oriole, Fairview, Henry Farm 43.778517 -79.346556 \n19 Bayview Village 43.786947 -79.385975 \n20 Silver Hills, York Mills 43.757490 -79.374714 \n21 Willowdale, Newtonbrook 43.789053 -79.408493 \n22 Willowdale South 43.770120 -79.408493 \n23 York Mills West 43.752758 -79.400049 \n24 Willowdale West 43.782736 -79.442259 \n25 Parkwoods 43.753259 -79.329656 \n26 Don Mills North 43.745906 -79.352188 \n27 Flemingdon Park, Don Mills South 43.725900 -79.340923 \n28 Downsview North, Wilson Heights, Bathurst Manor 43.754328 -79.442259 \n29 Northwood Park, York University 43.767980 -79.487262 \n.. ... ... ... \n73 Humewood-Cedarvale 43.693781 -79.428191 \n74 Caledonia-Fairbanks 43.689026 -79.453512 \n75 Christie 43.669542 -79.422564 \n76 Dovercourt Village, Dufferin 43.669005 -79.442259 \n77 Trinity, Little Portugal 43.647927 -79.419750 \n78 Parkdale Village, Brockton, Exhibition Place 43.636847 -79.428191 \n79 Downsview, North Park, Upwood Park 43.713756 -79.490074 \n80 Silverthorn, Mount Dennis, Keelesdale, Del Ray 43.691116 -79.476013 \n81 The Junction North, Runnymede 43.673185 -79.487262 \n82 The Junction South, High Park 43.661608 -79.464763 \n83 Parkdale, Roncesvalles 43.648960 -79.456325 \n84 Swansea, Runnymede 43.651571 -79.484450 \n85 Queen's Park 43.662301 -79.389494 \n86 Canada Post Gateway Processing Centre 43.636966 -79.615819 \n87 Business Reply Mail Processing Centre 969 Eastern 43.662744 -79.321558 \n88 New Toronto, Mimico South, Humber Bay Shores 43.605647 -79.501321 \n89 Alderwood, Long Branch 43.602414 -79.543484 \n90 The Kingsway, Old Mill North, Montgomery Road 43.653654 -79.506944 \n91 Mimico NE, Royal York South East, Sunnylea, Ki... 43.636258 -79.498509 \n92 Royal York South West, Mimico NW, The Queenswa... 43.628841 -79.520999 \n93 Queen's Park 43.667856 -79.532242 \n94 West Deane Park, Cloverdale, Martin Grove, Pri... 43.650943 -79.554724 \n95 Bloordale Gardens, Old Burnhamthorpe, Eringate... 43.643515 -79.577201 \n96 Humber Summit 43.756303 -79.565963 \n97 Humberlea, Emery 43.724766 -79.532242 \n98 Weston 43.706876 -79.518188 \n99 Westmount 43.696319 -79.532242 \n100 Martin Grove Gardens, Kingsview Village, St. P... 43.688905 -79.554724 \n101 Albion Gardens, Mount Olive, Jamestown, Beaumo... 43.739416 -79.588437 \n102 Northwest 43.706748 -79.594054 \n\n[103 rows x 5 columns]", "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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PostalCodeBoroughNeighborhoodLatitudeLongitude
0M1BScarboroughRouge, Malvern43.806686-79.194353
1M1CScarboroughRouge Hill, Highland Creek, Port Union43.784535-79.160497
2M1EScarboroughGuildwood, Morningside, West Hill43.763573-79.188711
3M1GScarboroughWoburn43.770992-79.216917
4M1HScarboroughCedarbrae43.773136-79.239476
5M1JScarboroughScarborough Village43.744734-79.239476
6M1KScarboroughKennedy Park, East Birchmount Park, Ionview43.727929-79.262029
7M1LScarboroughOakridge, Clairlea, Golden Mile43.711112-79.284577
8M1MScarboroughScarborough Village West, Cliffcrest, Cliffside43.716316-79.239476
9M1NScarboroughCliffside West, Birch Cliff43.692657-79.264848
10M1PScarboroughDorset Park, Wexford Heights, Scarborough Town...43.757410-79.273304
11M1RScarboroughWexford, Maryvale43.750072-79.295849
12M1SScarboroughAgincourt43.794200-79.262029
13M1TScarboroughTam O'Shanter, Clarks Corners, Sullivan43.781638-79.304302
14M1VScarboroughSteeles East, L'Amoreaux East, Milliken, Aginc...43.815252-79.284577
15M1WScarboroughL'Amoreaux West43.799525-79.318389
16M1XScarboroughUpper Rouge43.836125-79.205636
17M2HNorth YorkHillcrest Village43.803762-79.363452
18M2JNorth YorkOriole, Fairview, Henry Farm43.778517-79.346556
19M2KNorth YorkBayview Village43.786947-79.385975
20M2LNorth YorkSilver Hills, York Mills43.757490-79.374714
21M2MNorth YorkWillowdale, Newtonbrook43.789053-79.408493
22M2NNorth YorkWillowdale South43.770120-79.408493
23M2PNorth YorkYork Mills West43.752758-79.400049
24M2RNorth YorkWillowdale West43.782736-79.442259
25M3ANorth YorkParkwoods43.753259-79.329656
26M3BNorth YorkDon Mills North43.745906-79.352188
27M3CNorth YorkFlemingdon Park, Don Mills South43.725900-79.340923
28M3HNorth YorkDownsview North, Wilson Heights, Bathurst Manor43.754328-79.442259
29M3JNorth YorkNorthwood Park, York University43.767980-79.487262
..................
73M6CYorkHumewood-Cedarvale43.693781-79.428191
74M6EYorkCaledonia-Fairbanks43.689026-79.453512
75M6GDowntown TorontoChristie43.669542-79.422564
76M6HWest TorontoDovercourt Village, Dufferin43.669005-79.442259
77M6JWest TorontoTrinity, Little Portugal43.647927-79.419750
78M6KWest TorontoParkdale Village, Brockton, Exhibition Place43.636847-79.428191
79M6LNorth YorkDownsview, North Park, Upwood Park43.713756-79.490074
80M6MYorkSilverthorn, Mount Dennis, Keelesdale, Del Ray43.691116-79.476013
81M6NYorkThe Junction North, Runnymede43.673185-79.487262
82M6PWest TorontoThe Junction South, High Park43.661608-79.464763
83M6RWest TorontoParkdale, Roncesvalles43.648960-79.456325
84M6SWest TorontoSwansea, Runnymede43.651571-79.484450
85M7ADowntown TorontoQueen's Park43.662301-79.389494
86M7RMississaugaCanada Post Gateway Processing Centre43.636966-79.615819
87M7YEast TorontoBusiness Reply Mail Processing Centre 969 Eastern43.662744-79.321558
88M8VEtobicokeNew Toronto, Mimico South, Humber Bay Shores43.605647-79.501321
89M8WEtobicokeAlderwood, Long Branch43.602414-79.543484
90M8XEtobicokeThe Kingsway, Old Mill North, Montgomery Road43.653654-79.506944
91M8YEtobicokeMimico NE, Royal York South East, Sunnylea, Ki...43.636258-79.498509
92M8ZEtobicokeRoyal York South West, Mimico NW, The Queenswa...43.628841-79.520999
93M9AQueen's ParkQueen's Park43.667856-79.532242
94M9BEtobicokeWest Deane Park, Cloverdale, Martin Grove, Pri...43.650943-79.554724
95M9CEtobicokeBloordale Gardens, Old Burnhamthorpe, Eringate...43.643515-79.577201
96M9LNorth YorkHumber Summit43.756303-79.565963
97M9MNorth YorkHumberlea, Emery43.724766-79.532242
98M9NYorkWeston43.706876-79.518188
99M9PEtobicokeWestmount43.696319-79.532242
100M9REtobicokeMartin Grove Gardens, Kingsview Village, St. P...43.688905-79.554724
101M9VEtobicokeAlbion Gardens, Mount Olive, Jamestown, Beaumo...43.739416-79.588437
102M9WEtobicokeNorthwest43.706748-79.594054
\n

103 rows \u00d7 5 columns

\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "# Part - 3 of this Project"}, {"metadata": {}, "cell_type": "markdown", "source": "### Objective\nExploring and clustering the neighborhoods in Toronto for only those boroughs that contains word Toronto in its name."}, {"metadata": {}, "cell_type": "code", "source": "# Getting Latitude and Longitude of Toronto City.\n!conda install -c conda-forge geopy --yes # Installing geopy library, this library helps in getting Latitude and Longitude of a given address.\nfrom geopy.geocoders import Nominatim # Nominatim converts an address into latitude and longitude values.", "execution_count": 10, "outputs": [{"output_type": "stream", "text": "Solving environment: done\n\n## Package Plan ##\n\n environment location: /opt/conda/envs/Python36\n\n added / updated specs: \n - geopy\n\n\nThe following packages will be downloaded:\n\n package | build\n ---------------------------|-----------------\n ca-certificates-2019.11.28 | hecc5488_0 145 KB conda-forge\n certifi-2019.11.28 | py36_0 149 KB conda-forge\n openssl-1.1.1d | h516909a_0 2.1 MB conda-forge\n geographiclib-1.50 | py_0 34 KB conda-forge\n geopy-1.21.0 | py_0 58 KB conda-forge\n ------------------------------------------------------------\n Total: 2.5 MB\n\nThe following NEW packages will be INSTALLED:\n\n geographiclib: 1.50-py_0 conda-forge\n geopy: 1.21.0-py_0 conda-forge\n\nThe following packages will be UPDATED:\n\n ca-certificates: 2019.11.27-0 --> 2019.11.28-hecc5488_0 conda-forge\n certifi: 2019.11.28-py36_0 --> 2019.11.28-py36_0 conda-forge\n\nThe following packages will be DOWNGRADED:\n\n openssl: 1.1.1d-h7b6447c_3 --> 1.1.1d-h516909a_0 conda-forge\n\n\nDownloading and Extracting Packages\nca-certificates-2019 | 145 KB | ##################################### | 100% \ncertifi-2019.11.28 | 149 KB | ##################################### | 100% \nopenssl-1.1.1d | 2.1 MB | ##################################### | 100% \ngeographiclib-1.50 | 34 KB | ##################################### | 100% \ngeopy-1.21.0 | 58 KB | ##################################### | 100% \nPreparing transaction: done\nVerifying transaction: done\nExecuting transaction: done\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "code", "source": "address = 'Toronto, CA'\n\ngeolocator = Nominatim(user_agent=\"Toronto_explorer\")\nTo_location = geolocator.geocode(address)\nTo_latitude = To_location.latitude\nTo_longitude = To_location.longitude\nprint('The geograpical coordinate of Toronto City are {}, {}.'.format(To_latitude, To_longitude))", "execution_count": 11, "outputs": [{"output_type": "stream", "text": "The geograpical coordinate of Toronto City are 43.653963, -79.387207.\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "### Create a map of Toronto City with all neighborhoods superimposed on top."}, {"metadata": {}, "cell_type": "code", "source": "!conda install -c conda-forge folium=0.5.0 --yes # Installing Folium Library \nimport folium # map rendering library", "execution_count": 12, "outputs": [{"output_type": "stream", "text": "Solving environment: done\n\n## Package Plan ##\n\n environment location: /opt/conda/envs/Python36\n\n added / updated specs: \n - folium=0.5.0\n\n\nThe following packages will be downloaded:\n\n package | build\n ---------------------------|-----------------\n altair-4.0.1 | py_0 575 KB conda-forge\n vincent-0.4.4 | py_1 28 KB conda-forge\n branca-0.3.1 | py_0 25 KB conda-forge\n folium-0.5.0 | py_0 45 KB conda-forge\n ------------------------------------------------------------\n Total: 673 KB\n\nThe following NEW packages will be INSTALLED:\n\n altair: 4.0.1-py_0 conda-forge\n branca: 0.3.1-py_0 conda-forge\n folium: 0.5.0-py_0 conda-forge\n vincent: 0.4.4-py_1 conda-forge\n\n\nDownloading and Extracting Packages\naltair-4.0.1 | 575 KB | ##################################### | 100% \nvincent-0.4.4 | 28 KB | ##################################### | 100% \nbranca-0.3.1 | 25 KB | ##################################### | 100% \nfolium-0.5.0 | 45 KB | ##################################### | 100% \nPreparing transaction: done\nVerifying transaction: done\nExecuting transaction: done\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "code", "source": "Toronto_map = folium.Map(location=[To_latitude,To_longitude], zoom_start = 11)\n\n# add markers to map\nfor lat, lng, borough, neighborhood in zip(Toronto_df['Latitude'], Toronto_df['Longitude'], Toronto_df['Borough'], Toronto_df['Neighborhood']):\n label = '{}, {}'.format(neighborhood, borough)\n label = folium.Popup(label, parse_html=True)\n folium.CircleMarker(\n [lat, lng],\n radius=5,\n popup=label,\n color='blue',\n fill=True,\n fill_color='#3186cc',\n fill_opacity=0.7,\n parse_html=False).add_to(Toronto_map) \n \nToronto_map", "execution_count": 13, "outputs": [{"output_type": "execute_result", "execution_count": 13, "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "As per the objective I have to show only those neighborhoods whoose borough name contain Toronto word"}, {"metadata": {}, "cell_type": "code", "source": "# Filtering Data Set, Considering only those rows where column Borough contains Toronto Word.\n\nNew_Toronto_df = Toronto_df[Toronto_df['Borough'].apply(lambda x: 'Toronto' in str(x))]\nNew_Toronto_df.head()", "execution_count": 14, "outputs": [{"output_type": "execute_result", "execution_count": 14, "data": {"text/plain": " PostalCode Borough Neighborhood Latitude \\\n37 M4E East Toronto The Beaches 43.676357 \n41 M4K East Toronto Riverdale, The Danforth West 43.679557 \n42 M4L East Toronto The Beaches West, India Bazaar 43.668999 \n43 M4M East Toronto Studio District 43.659526 \n44 M4N Central Toronto Lawrence Park 43.728020 \n\n Longitude \n37 -79.293031 \n41 -79.352188 \n42 -79.315572 \n43 -79.340923 \n44 -79.388790 ", "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
PostalCodeBoroughNeighborhoodLatitudeLongitude
37M4EEast TorontoThe Beaches43.676357-79.293031
41M4KEast TorontoRiverdale, The Danforth West43.679557-79.352188
42M4LEast TorontoThe Beaches West, India Bazaar43.668999-79.315572
43M4MEast TorontoStudio District43.659526-79.340923
44M4NCentral TorontoLawrence Park43.728020-79.388790
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "# list of unique Borough in New Data set\nBorough_lst = New_Toronto_df.Borough.unique().tolist()\nBorough_lst", "execution_count": 15, "outputs": [{"output_type": "execute_result", "execution_count": 15, "data": {"text/plain": "['East Toronto', 'Central Toronto', 'Downtown Toronto', 'West Toronto']"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "### Creating map of Toronto city with new defined neighborhood superimposed on top"}, {"metadata": {}, "cell_type": "code", "source": "Toronto_Map = folium.Map(location=[To_latitude,To_longitude],zoom_start=11)\n\nfor lat,lon,borough,neighborhood in zip(New_Toronto_df['Latitude'],New_Toronto_df['Longitude'],New_Toronto_df['Borough'],New_Toronto_df['Neighborhood']):\n label = '{}, {}'.format(neighborhood, borough)\n label = folium.Popup(label,parse_html=True)\n folium.CircleMarker(\n [lat,lon],\n radius=5,\n popup=label,\n color='blue',\n fill=True,\n fill_color='#3186cc',\n fill_opacity=0.7,\n parse_html=False).add_to(Toronto_Map)\n\nToronto_Map", "execution_count": 16, "outputs": [{"output_type": "execute_result", "execution_count": 16, "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Next, we are going to start utilizing the Foursquare API to explore the neighborhoods and segment them."}, {"metadata": {}, "cell_type": "markdown", "source": "### Define Foursquare Credentials and Version"}, {"metadata": {}, "cell_type": "code", "source": "CLIENT_ID = 'MUINF3SJELTWX0T2R3GWA5P5R3QYAGI2PDFGFR0HCERWTFNH' # my Foursquare ID\nCLIENT_SECRET = 'TNBO5TIGKMZR0RR1ARMSUHBMPJ2V0JZBNZQ2G2220FAMS05U' # my Foursquare Secret\nVERSION = '20180605' # Foursquare API version\n\nprint('My credentails:')\nprint('CLIENT_ID: ' + CLIENT_ID)\nprint('CLIENT_SECRET:' + CLIENT_SECRET)", "execution_count": 17, "outputs": [{"output_type": "stream", "text": "My credentails:\nCLIENT_ID: MUINF3SJELTWX0T2R3GWA5P5R3QYAGI2PDFGFR0HCERWTFNH\nCLIENT_SECRET:TNBO5TIGKMZR0RR1ARMSUHBMPJ2V0JZBNZQ2G2220FAMS05U\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "### Let's explore the first neighborhood in our dataframe.\nGet the neighborhood's name."}, {"metadata": {}, "cell_type": "code", "source": "New_Toronto_df = New_Toronto_df.reset_index(drop=True)\nNew_Toronto_df.loc[0, 'Neighborhood']", "execution_count": 18, "outputs": [{"output_type": "execute_result", "execution_count": 18, "data": {"text/plain": "'The Beaches'"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Get the latitude and longitude values of The Beaches."}, {"metadata": {}, "cell_type": "code", "source": "Beaches_latitude = New_Toronto_df.loc[0, 'Latitude'] # neighborhood latitude value\nBeaches_longitude = New_Toronto_df.loc[0, 'Longitude'] # neighborhood longitude value\n\nprint('Latitude and longitude values of The Beaches are {}, {}.'.format(\n Beaches_latitude, \n Beaches_longitude))", "execution_count": 19, "outputs": [{"output_type": "stream", "text": "Latitude and longitude values of The Beaches are 43.67635739999999, -79.2930312.\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "### Now, let's get the top 100 venues that are in Marble Hill within a radius of 500 meters."}, {"metadata": {}, "cell_type": "code", "source": "# First, let's create the GET request URL. Name your URL url.\nLIMIT = 100 # no. of venues\nradius = 500\n\nurl = '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 Beaches_latitude, \n Beaches_longitude, \n radius, \n LIMIT)\n\nurl ", "execution_count": 20, "outputs": [{"output_type": "execute_result", "execution_count": 20, "data": {"text/plain": "'https://api.foursquare.com/v2/venues/explore?&client_id=MUINF3SJELTWX0T2R3GWA5P5R3QYAGI2PDFGFR0HCERWTFNH&client_secret=TNBO5TIGKMZR0RR1ARMSUHBMPJ2V0JZBNZQ2G2220FAMS05U&v=20180605&ll=43.67635739999999,-79.2930312&radius=500&limit=100'"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Send the GET request and examine the resutls"}, {"metadata": {}, "cell_type": "code", "source": "import requests # importing request handling library\n\nresults = requests.get(url).json()\nresults", "execution_count": 21, "outputs": [{"output_type": "execute_result", "execution_count": 21, "data": {"text/plain": "{'meta': {'code': 200, 'requestId': '5e38fe3e006dce001ce3e09a'},\n 'response': {'headerLocation': 'The Beaches',\n 'headerFullLocation': 'The Beaches, Toronto',\n 'headerLocationGranularity': 'neighborhood',\n 'totalResults': 5,\n 'suggestedBounds': {'ne': {'lat': 43.680857404499996,\n 'lng': -79.28682091449052},\n 'sw': {'lat': 43.67185739549999, 'lng': -79.29924148550948}},\n 'groups': [{'type': 'Recommended Places',\n 'name': 'recommended',\n 'items': [{'reasons': {'count': 0,\n 'items': [{'summary': 'This spot is popular',\n 'type': 'general',\n 'reasonName': 'globalInteractionReason'}]},\n 'venue': {'id': '4bd461bc77b29c74a07d9282',\n 'name': 'Glen Manor Ravine',\n 'location': {'address': 'Glen Manor',\n 'crossStreet': 'Queen St.',\n 'lat': 43.67682094413784,\n 'lng': -79.29394208780985,\n 'labeledLatLngs': [{'label': 'display',\n 'lat': 43.67682094413784,\n 'lng': -79.29394208780985}],\n 'distance': 89,\n 'cc': 'CA',\n 'city': 'Toronto',\n 'state': 'ON',\n 'country': 'Canada',\n 'formattedAddress': ['Glen Manor (Queen St.)',\n 'Toronto ON',\n 'Canada']},\n 'categories': [{'id': '4bf58dd8d48988d159941735',\n 'name': 'Trail',\n 'pluralName': 'Trails',\n 'shortName': 'Trail',\n 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/parks_outdoors/hikingtrail_',\n 'suffix': '.png'},\n 'primary': True}],\n 'photos': {'count': 0, 'groups': []}},\n 'referralId': 'e-0-4bd461bc77b29c74a07d9282-0'},\n {'reasons': {'count': 0,\n 'items': [{'summary': 'This spot is popular',\n 'type': 'general',\n 'reasonName': 'globalInteractionReason'}]},\n 'venue': {'id': '4ad4c062f964a52011f820e3',\n 'name': 'The Big Carrot Natural Food Market',\n 'location': {'address': '125 Southwood Dr',\n 'lat': 43.678879,\n 'lng': -79.297734,\n 'labeledLatLngs': [{'label': 'display',\n 'lat': 43.678879,\n 'lng': -79.297734}],\n 'distance': 471,\n 'postalCode': 'M4E 0B8',\n 'cc': 'CA',\n 'city': 'Toronto',\n 'state': 'ON',\n 'country': 'Canada',\n 'formattedAddress': ['125 Southwood Dr',\n 'Toronto ON M4E 0B8',\n 'Canada']},\n 'categories': [{'id': '50aa9e744b90af0d42d5de0e',\n 'name': 'Health Food Store',\n 'pluralName': 'Health Food Stores',\n 'shortName': 'Health Food Store',\n 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/shops/food_grocery_',\n 'suffix': '.png'},\n 'primary': True}],\n 'photos': {'count': 0, 'groups': []},\n 'venuePage': {'id': '75150878'}},\n 'referralId': 'e-0-4ad4c062f964a52011f820e3-1'},\n {'reasons': {'count': 0,\n 'items': [{'summary': 'This spot is popular',\n 'type': 'general',\n 'reasonName': 'globalInteractionReason'}]},\n 'venue': {'id': '4b8daea1f964a520480833e3',\n 'name': 'Grover Pub and Grub',\n 'location': {'address': '676 Kingston Rd.',\n 'crossStreet': 'at Main St.',\n 'lat': 43.679181434941015,\n 'lng': -79.29721535878515,\n 'labeledLatLngs': [{'label': 'display',\n 'lat': 43.679181434941015,\n 'lng': -79.29721535878515}],\n 'distance': 460,\n 'postalCode': 'M4E 1R4',\n 'cc': 'CA',\n 'city': 'Toronto',\n 'state': 'ON',\n 'country': 'Canada',\n 'formattedAddress': ['676 Kingston Rd. (at Main St.)',\n 'Toronto ON M4E 1R4',\n 'Canada']},\n 'categories': [{'id': '4bf58dd8d48988d11b941735',\n 'name': 'Pub',\n 'pluralName': 'Pubs',\n 'shortName': 'Pub',\n 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/nightlife/pub_',\n 'suffix': '.png'},\n 'primary': True}],\n 'photos': {'count': 0, 'groups': []}},\n 'referralId': 'e-0-4b8daea1f964a520480833e3-2'},\n {'reasons': {'count': 0,\n 'items': [{'summary': 'This spot is popular',\n 'type': 'general',\n 'reasonName': 'globalInteractionReason'}]},\n 'venue': {'id': '4df91c4bae60f95f82229ad5',\n 'name': 'Upper Beaches',\n 'location': {'lat': 43.68056321147582,\n 'lng': -79.2928688743688,\n 'labeledLatLngs': [{'label': 'display',\n 'lat': 43.68056321147582,\n 'lng': -79.2928688743688}],\n 'distance': 468,\n 'cc': 'CA',\n 'city': 'Toronto',\n 'state': 'ON',\n 'country': 'Canada',\n 'formattedAddress': ['Toronto ON', 'Canada']},\n 'categories': [{'id': '4f2a25ac4b909258e854f55f',\n 'name': 'Neighborhood',\n 'pluralName': 'Neighborhoods',\n 'shortName': 'Neighborhood',\n 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/parks_outdoors/neighborhood_',\n 'suffix': '.png'},\n 'primary': True}],\n 'photos': {'count': 0, 'groups': []}},\n 'referralId': 'e-0-4df91c4bae60f95f82229ad5-3'},\n {'reasons': {'count': 0,\n 'items': [{'summary': 'This spot is popular',\n 'type': 'general',\n 'reasonName': 'globalInteractionReason'}]},\n 'venue': {'id': '4dbc53541e72b351caafda72',\n 'name': 'Seaspray Restaurant',\n 'location': {'address': '629 Kingston Rd',\n 'crossStreet': 'at Main St',\n 'lat': 43.678887885937094,\n 'lng': -79.29816674246032,\n 'labeledLatLngs': [{'label': 'display',\n 'lat': 43.678887885937094,\n 'lng': -79.29816674246032}],\n 'distance': 500,\n 'cc': 'CA',\n 'city': 'Toronto',\n 'state': 'ON',\n 'country': 'Canada',\n 'formattedAddress': ['629 Kingston Rd (at Main St)',\n 'Toronto ON',\n 'Canada']},\n 'categories': [{'id': '4bf58dd8d48988d142941735',\n 'name': 'Asian Restaurant',\n 'pluralName': 'Asian Restaurants',\n 'shortName': 'Asian',\n 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/asian_',\n 'suffix': '.png'},\n 'primary': True}],\n 'photos': {'count': 0, 'groups': []}},\n 'referralId': 'e-0-4dbc53541e72b351caafda72-4'}]}]}}"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "# function that extracts the category of the venue\ndef get_category_type(row):\n try:\n categories_list = row['categories']\n except:\n categories_list = row['venue.categories']\n \n if len(categories_list) == 0:\n return None\n else:\n return categories_list[0]['name']", "execution_count": 22, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "Now we are ready to clean the json and structure it into a pandas dataframe."}, {"metadata": {}, "cell_type": "code", "source": "from pandas.io.json import json_normalize # tranform JSON file into a pandas dataframe\n\nvenues = results['response']['groups'][0]['items']\n \nnearby_venues = json_normalize(venues) # flatten JSON\n\n# filter columns\nfiltered_columns = ['venue.name', 'venue.categories', 'venue.location.lat', 'venue.location.lng']\nnearby_venues =nearby_venues.loc[:, filtered_columns]\n\n# filter the category for each row\nnearby_venues['venue.categories'] = nearby_venues.apply(get_category_type, axis=1)\n\n# clean columns\nnearby_venues.columns = [col.split(\".\")[-1] for col in nearby_venues.columns]\n\nnearby_venues.head()", "execution_count": 23, "outputs": [{"output_type": "execute_result", "execution_count": 23, "data": {"text/plain": " name categories lat lng\n0 Glen Manor Ravine Trail 43.676821 -79.293942\n1 The Big Carrot Natural Food Market Health Food Store 43.678879 -79.297734\n2 Grover Pub and Grub Pub 43.679181 -79.297215\n3 Upper Beaches Neighborhood 43.680563 -79.292869\n4 Seaspray Restaurant Asian Restaurant 43.678888 -79.298167", "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
namecategorieslatlng
0Glen Manor RavineTrail43.676821-79.293942
1The Big Carrot Natural Food MarketHealth Food Store43.678879-79.297734
2Grover Pub and GrubPub43.679181-79.297215
3Upper BeachesNeighborhood43.680563-79.292869
4Seaspray RestaurantAsian Restaurant43.678888-79.298167
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "And how many venues were returned by Foursquare?"}, {"metadata": {}, "cell_type": "code", "source": "print('{} venues were returned by Foursquare.'.format(nearby_venues.shape[0]))", "execution_count": 24, "outputs": [{"output_type": "stream", "text": "5 venues were returned by Foursquare.\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "# Explore Neighborhoods in The Beaches"}, {"metadata": {}, "cell_type": "markdown", "source": "Let's create a function to repeat the same process to all the neighborhoods in Manhattan"}, {"metadata": {}, "cell_type": "code", "source": "def getNearbyVenues(names, latitudes, longitudes, radius=500):\n \n venues_list=[]\n for name, lat, lng in zip(names, latitudes, longitudes):\n print('Processing ',name,'.....')\n \n # create the API request URL\n url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(\n CLIENT_ID, \n CLIENT_SECRET, \n VERSION, \n lat, \n lng, \n radius, \n LIMIT)\n \n # make the GET request\n results = requests.get(url).json()[\"response\"]['groups'][0]['items']\n \n # return only relevant information for each nearby venue\n venues_list.append([(\n name, \n lat, \n lng, \n v['venue']['name'], \n v['venue']['location']['lat'], \n v['venue']['location']['lng'], \n v['venue']['categories'][0]['name']) for v in results])\n\n nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])\n nearby_venues.columns = ['Neighborhood', \n 'Neighborhood Latitude', \n 'Neighborhood Longitude', \n 'Venue', \n 'Venue Latitude', \n 'Venue Longitude', \n 'Venue Category']\n \n return(nearby_venues)", "execution_count": 25, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "### Now write the code to run the above function on each neighborhood and create a new dataframe called Filtered_Toronto_Venues."}, {"metadata": {}, "cell_type": "code", "source": "Filtered_Toronto_Venues = getNearbyVenues(names=New_Toronto_df['Neighborhood'],\n latitudes=New_Toronto_df['Latitude'],\n longitudes=New_Toronto_df['Longitude']\n )\nFiltered_Toronto_Venues.head()", "execution_count": 26, "outputs": [{"output_type": "stream", "text": "Processing The Beaches .....\nProcessing Riverdale, The Danforth West .....\nProcessing The Beaches West, India Bazaar .....\nProcessing Studio District .....\nProcessing Lawrence Park .....\nProcessing Davisville North .....\nProcessing North Toronto West .....\nProcessing Davisville .....\nProcessing Summerhill East, Moore Park .....\nProcessing South Hill, Summerhill West, Rathnelly, Forest Hill SE, Deer Park .....\nProcessing Rosedale .....\nProcessing St. James Town, Cabbagetown .....\nProcessing Church and Wellesley .....\nProcessing Harbourfront .....\nProcessing Ryerson, Garden District .....\nProcessing St. James Town .....\nProcessing Berczy Park .....\nProcessing Central Bay Street .....\nProcessing Richmond, Adelaide, King .....\nProcessing Toronto Islands, Harbourfront East, Union Station .....\nProcessing Design Exchange, Toronto Dominion Centre .....\nProcessing Victoria Hotel, Commerce Court .....\nProcessing Roselawn .....\nProcessing Forest Hill West, Forest Hill North .....\nProcessing The Annex, North Midtown, Yorkville .....\nProcessing Harbord, University of Toronto .....\nProcessing Chinatown, Kensington Market, Grange Park .....\nProcessing Harbourfront West, CN Tower, Island airport, Railway Lands, Bathurst Quay, South Niagara, King and Spadina .....\nProcessing Stn A PO Boxes 25 The Esplanade .....\nProcessing First Canadian Place, Underground city .....\nProcessing Christie .....\nProcessing Dovercourt Village, Dufferin .....\nProcessing Trinity, Little Portugal .....\nProcessing Parkdale Village, Brockton, Exhibition Place .....\nProcessing The Junction South, High Park .....\nProcessing Parkdale, Roncesvalles .....\nProcessing Swansea, Runnymede .....\nProcessing Queen's Park .....\nProcessing Business Reply Mail Processing Centre 969 Eastern .....\n", "name": "stdout"}, {"output_type": "execute_result", "execution_count": 26, "data": {"text/plain": " Neighborhood Neighborhood Latitude Neighborhood Longitude \\\n0 The Beaches 43.676357 -79.293031 \n1 The Beaches 43.676357 -79.293031 \n2 The Beaches 43.676357 -79.293031 \n3 The Beaches 43.676357 -79.293031 \n4 The Beaches 43.676357 -79.293031 \n\n Venue Venue Latitude Venue Longitude \\\n0 Glen Manor Ravine 43.676821 -79.293942 \n1 The Big Carrot Natural Food Market 43.678879 -79.297734 \n2 Grover Pub and Grub 43.679181 -79.297215 \n3 Upper Beaches 43.680563 -79.292869 \n4 Seaspray Restaurant 43.678888 -79.298167 \n\n Venue Category \n0 Trail \n1 Health Food Store \n2 Pub \n3 Neighborhood \n4 Asian 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 LatitudeVenue LongitudeVenue Category
0The Beaches43.676357-79.293031Glen Manor Ravine43.676821-79.293942Trail
1The Beaches43.676357-79.293031The Big Carrot Natural Food Market43.678879-79.297734Health Food Store
2The Beaches43.676357-79.293031Grover Pub and Grub43.679181-79.297215Pub
3The Beaches43.676357-79.293031Upper Beaches43.680563-79.292869Neighborhood
4The Beaches43.676357-79.293031Seaspray Restaurant43.678888-79.298167Asian Restaurant
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "#### Let's check the size of the resulting dataframe"}, {"metadata": {}, "cell_type": "code", "source": "print(Filtered_Toronto_Venues.shape)", "execution_count": 27, "outputs": [{"output_type": "stream", "text": "(1714, 7)\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "Let's check how many venues were returned for each neighborhood"}, {"metadata": {}, "cell_type": "code", "source": "Filtered_Toronto_Venues.groupby('Neighborhood').count().iloc[:,0]", "execution_count": 28, "outputs": [{"output_type": "execute_result", "execution_count": 28, "data": {"text/plain": "Neighborhood\nBerczy Park 56\nBusiness Reply Mail Processing Centre 969 Eastern 16\nCentral Bay Street 83\nChinatown, Kensington Market, Grange Park 87\nChristie 19\nChurch and Wellesley 82\nDavisville 32\nDavisville North 8\nDesign Exchange, Toronto Dominion Centre 100\nDovercourt Village, Dufferin 16\nFirst Canadian Place, Underground city 100\nForest Hill West, Forest Hill North 4\nHarbord, University of Toronto 37\nHarbourfront 47\nHarbourfront West, CN Tower, Island airport, Railway Lands, Bathurst Quay, South Niagara, King and Spadina 16\nLawrence Park 3\nNorth Toronto West 21\nParkdale Village, Brockton, Exhibition Place 23\nParkdale, Roncesvalles 14\nQueen's Park 39\nRichmond, Adelaide, King 100\nRiverdale, The Danforth West 42\nRosedale 4\nRoselawn 3\nRyerson, Garden District 100\nSouth Hill, Summerhill West, Rathnelly, Forest Hill SE, Deer Park 15\nSt. James Town 100\nSt. James Town, Cabbagetown 47\nStn A PO Boxes 25 The Esplanade 95\nStudio District 42\nSummerhill East, Moore Park 1\nSwansea, Runnymede 40\nThe Annex, North Midtown, Yorkville 22\nThe Beaches 5\nThe Beaches West, India Bazaar 18\nThe Junction South, High Park 24\nToronto Islands, Harbourfront East, Union Station 100\nTrinity, Little Portugal 53\nVictoria Hotel, Commerce Court 100\nName: Neighborhood Latitude, dtype: int64"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "## Let's find out how many unique categories can be curated from all the returned venues"}, {"metadata": {}, "cell_type": "code", "source": "print('There are {} uniques categories.'.format(len(Filtered_Toronto_Venues['Venue Category'].unique())))", "execution_count": 29, "outputs": [{"output_type": "stream", "text": "There are 230 uniques categories.\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "# Analyze Each Neighborhood"}, {"metadata": {}, "cell_type": "code", "source": "# one hot encoding\nToronto_onehot = pd.get_dummies(Filtered_Toronto_Venues[['Venue Category']], prefix=\"\", prefix_sep=\"\")\n\n# add neighborhood column back to dataframe\nToronto_onehot['Neighborhood'] = Filtered_Toronto_Venues['Neighborhood'] \n\n# move neighborhood column to the first column\nfixed_columns = [Toronto_onehot.columns[-1]] + list(Toronto_onehot.columns[:-1])\nToronto_onehot = Toronto_onehot[fixed_columns]\n\nToronto_onehot.head()", "execution_count": 30, "outputs": [{"output_type": "execute_result", "execution_count": 30, "data": {"text/plain": " Yoga Studio Afghan Restaurant Airport Airport Food Court Airport Gate \\\n0 0 0 0 0 0 \n1 0 0 0 0 0 \n2 0 0 0 0 0 \n3 0 0 0 0 0 \n4 0 0 0 0 0 \n\n Airport Lounge Airport Service Airport Terminal American Restaurant \\\n0 0 0 0 0 \n1 0 0 0 0 \n2 0 0 0 0 \n3 0 0 0 0 \n4 0 0 0 0 \n\n Antique Shop ... Theater Theme Restaurant Toy / Game Store Trail \\\n0 0 ... 0 0 0 1 \n1 0 ... 0 0 0 0 \n2 0 ... 0 0 0 0 \n3 0 ... 0 0 0 0 \n4 0 ... 0 0 0 0 \n\n Train Station Vegetarian / Vegan Restaurant Video Game Store \\\n0 0 0 0 \n1 0 0 0 \n2 0 0 0 \n3 0 0 0 \n4 0 0 0 \n\n Vietnamese Restaurant Wine Bar Women's Store \n0 0 0 0 \n1 0 0 0 \n2 0 0 0 \n3 0 0 0 \n4 0 0 0 \n\n[5 rows x 230 columns]", "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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Yoga StudioAfghan RestaurantAirportAirport Food CourtAirport GateAirport LoungeAirport ServiceAirport TerminalAmerican RestaurantAntique Shop...TheaterTheme RestaurantToy / Game StoreTrailTrain StationVegetarian / Vegan RestaurantVideo Game StoreVietnamese RestaurantWine BarWomen's Store
00000000000...0001000000
10000000000...0000000000
20000000000...0000000000
30000000000...0000000000
40000000000...0000000000
\n

5 rows \u00d7 230 columns

\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Next, let's group rows by neighborhood and by taking the mean of the frequency of occurrence of each category"}, {"metadata": {}, "cell_type": "code", "source": "Toronto_grouped = Toronto_onehot.groupby('Neighborhood').mean().reset_index()\nToronto_grouped", "execution_count": 31, "outputs": [{"output_type": "execute_result", "execution_count": 31, "data": {"text/plain": " Neighborhood Yoga Studio \\\n0 Berczy Park 0.000000 \n1 Business Reply Mail Processing Centre 969 Eastern 0.000000 \n2 Central Bay Street 0.012048 \n3 Chinatown, Kensington Market, Grange Park 0.000000 \n4 Christie 0.000000 \n5 Church and Wellesley 0.012195 \n6 Davisville 0.000000 \n7 Davisville North 0.000000 \n8 Design Exchange, Toronto Dominion Centre 0.000000 \n9 Dovercourt Village, Dufferin 0.000000 \n10 First Canadian Place, Underground city 0.000000 \n11 Forest Hill West, Forest Hill North 0.000000 \n12 Harbord, University of Toronto 0.027027 \n13 Harbourfront 0.021277 \n14 Harbourfront West, CN Tower, Island airport, R... 0.000000 \n15 Lawrence Park 0.000000 \n16 North Toronto West 0.047619 \n17 Parkdale Village, Brockton, Exhibition Place 0.043478 \n18 Parkdale, Roncesvalles 0.000000 \n19 Queen's Park 0.025641 \n20 Richmond, Adelaide, King 0.000000 \n21 Riverdale, The Danforth West 0.023810 \n22 Rosedale 0.000000 \n23 Roselawn 0.000000 \n24 Ryerson, Garden District 0.000000 \n25 South Hill, Summerhill West, Rathnelly, Forest... 0.000000 \n26 St. James Town 0.000000 \n27 St. James Town, Cabbagetown 0.000000 \n28 Stn A PO Boxes 25 The Esplanade 0.000000 \n29 Studio District 0.023810 \n30 Summerhill East, Moore Park 0.000000 \n31 Swansea, Runnymede 0.025000 \n32 The Annex, North Midtown, Yorkville 0.000000 \n33 The Beaches 0.000000 \n34 The Beaches West, India Bazaar 0.000000 \n35 The Junction South, High Park 0.000000 \n36 Toronto Islands, Harbourfront East, Union Station 0.000000 \n37 Trinity, Little Portugal 0.018868 \n38 Victoria Hotel, Commerce Court 0.000000 \n\n Afghan Restaurant Airport Airport Food Court Airport Gate \\\n0 0.000000 0.0000 0.0000 0.0000 \n1 0.000000 0.0000 0.0000 0.0000 \n2 0.000000 0.0000 0.0000 0.0000 \n3 0.000000 0.0000 0.0000 0.0000 \n4 0.000000 0.0000 0.0000 0.0000 \n5 0.012195 0.0000 0.0000 0.0000 \n6 0.000000 0.0000 0.0000 0.0000 \n7 0.000000 0.0000 0.0000 0.0000 \n8 0.000000 0.0000 0.0000 0.0000 \n9 0.000000 0.0000 0.0000 0.0000 \n10 0.000000 0.0000 0.0000 0.0000 \n11 0.000000 0.0000 0.0000 0.0000 \n12 0.000000 0.0000 0.0000 0.0000 \n13 0.000000 0.0000 0.0000 0.0000 \n14 0.000000 0.0625 0.0625 0.0625 \n15 0.000000 0.0000 0.0000 0.0000 \n16 0.000000 0.0000 0.0000 0.0000 \n17 0.000000 0.0000 0.0000 0.0000 \n18 0.000000 0.0000 0.0000 0.0000 \n19 0.000000 0.0000 0.0000 0.0000 \n20 0.000000 0.0000 0.0000 0.0000 \n21 0.000000 0.0000 0.0000 0.0000 \n22 0.000000 0.0000 0.0000 0.0000 \n23 0.000000 0.0000 0.0000 0.0000 \n24 0.000000 0.0000 0.0000 0.0000 \n25 0.000000 0.0000 0.0000 0.0000 \n26 0.000000 0.0000 0.0000 0.0000 \n27 0.000000 0.0000 0.0000 0.0000 \n28 0.000000 0.0000 0.0000 0.0000 \n29 0.000000 0.0000 0.0000 0.0000 \n30 0.000000 0.0000 0.0000 0.0000 \n31 0.000000 0.0000 0.0000 0.0000 \n32 0.000000 0.0000 0.0000 0.0000 \n33 0.000000 0.0000 0.0000 0.0000 \n34 0.000000 0.0000 0.0000 0.0000 \n35 0.000000 0.0000 0.0000 0.0000 \n36 0.000000 0.0000 0.0000 0.0000 \n37 0.000000 0.0000 0.0000 0.0000 \n38 0.000000 0.0000 0.0000 0.0000 \n\n Airport Lounge Airport Service Airport Terminal American Restaurant \\\n0 0.000 0.000 0.000 0.000000 \n1 0.000 0.000 0.000 0.000000 \n2 0.000 0.000 0.000 0.012048 \n3 0.000 0.000 0.000 0.000000 \n4 0.000 0.000 0.000 0.000000 \n5 0.000 0.000 0.000 0.012195 \n6 0.000 0.000 0.000 0.000000 \n7 0.000 0.000 0.000 0.000000 \n8 0.000 0.000 0.000 0.020000 \n9 0.000 0.000 0.000 0.000000 \n10 0.000 0.000 0.000 0.020000 \n11 0.000 0.000 0.000 0.000000 \n12 0.000 0.000 0.000 0.000000 \n13 0.000 0.000 0.000 0.000000 \n14 0.125 0.125 0.125 0.000000 \n15 0.000 0.000 0.000 0.000000 \n16 0.000 0.000 0.000 0.000000 \n17 0.000 0.000 0.000 0.000000 \n18 0.000 0.000 0.000 0.000000 \n19 0.000 0.000 0.000 0.000000 \n20 0.000 0.000 0.000 0.020000 \n21 0.000 0.000 0.000 0.023810 \n22 0.000 0.000 0.000 0.000000 \n23 0.000 0.000 0.000 0.000000 \n24 0.000 0.000 0.000 0.010000 \n25 0.000 0.000 0.000 0.066667 \n26 0.000 0.000 0.000 0.030000 \n27 0.000 0.000 0.000 0.021277 \n28 0.000 0.000 0.000 0.000000 \n29 0.000 0.000 0.000 0.047619 \n30 0.000 0.000 0.000 0.000000 \n31 0.000 0.000 0.000 0.000000 \n32 0.000 0.000 0.000 0.045455 \n33 0.000 0.000 0.000 0.000000 \n34 0.000 0.000 0.000 0.000000 \n35 0.000 0.000 0.000 0.000000 \n36 0.000 0.000 0.000 0.000000 \n37 0.000 0.000 0.000 0.000000 \n38 0.000 0.000 0.000 0.030000 \n\n ... Theater Theme Restaurant Toy / Game Store Trail Train Station \\\n0 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n1 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n2 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n3 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n4 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n5 ... 0.012195 0.012195 0.00000 0.00000 0.00 \n6 ... 0.000000 0.000000 0.03125 0.00000 0.00 \n7 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n8 ... 0.010000 0.000000 0.00000 0.00000 0.01 \n9 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n10 ... 0.010000 0.000000 0.00000 0.00000 0.01 \n11 ... 0.000000 0.000000 0.00000 0.25000 0.00 \n12 ... 0.027027 0.000000 0.00000 0.00000 0.00 \n13 ... 0.021277 0.000000 0.00000 0.00000 0.00 \n14 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n15 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n16 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n17 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n18 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n19 ... 0.025641 0.000000 0.00000 0.00000 0.00 \n20 ... 0.010000 0.000000 0.00000 0.00000 0.00 \n21 ... 0.000000 0.000000 0.00000 0.02381 0.00 \n22 ... 0.000000 0.000000 0.00000 0.25000 0.00 \n23 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n24 ... 0.020000 0.000000 0.01000 0.00000 0.00 \n25 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n26 ... 0.010000 0.000000 0.00000 0.00000 0.00 \n27 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n28 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n29 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n30 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n31 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n32 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n33 ... 0.000000 0.000000 0.00000 0.20000 0.00 \n34 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n35 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n36 ... 0.010000 0.000000 0.00000 0.00000 0.01 \n37 ... 0.018868 0.000000 0.00000 0.00000 0.00 \n38 ... 0.000000 0.000000 0.00000 0.00000 0.00 \n\n Vegetarian / Vegan Restaurant Video Game Store Vietnamese Restaurant \\\n0 0.017857 0.000000 0.000000 \n1 0.000000 0.000000 0.000000 \n2 0.012048 0.000000 0.000000 \n3 0.045977 0.000000 0.068966 \n4 0.000000 0.000000 0.000000 \n5 0.000000 0.000000 0.000000 \n6 0.000000 0.000000 0.000000 \n7 0.000000 0.000000 0.000000 \n8 0.010000 0.000000 0.000000 \n9 0.000000 0.000000 0.000000 \n10 0.010000 0.000000 0.000000 \n11 0.000000 0.000000 0.000000 \n12 0.000000 0.027027 0.000000 \n13 0.000000 0.000000 0.000000 \n14 0.000000 0.000000 0.000000 \n15 0.000000 0.000000 0.000000 \n16 0.000000 0.000000 0.000000 \n17 0.000000 0.000000 0.000000 \n18 0.000000 0.000000 0.000000 \n19 0.000000 0.000000 0.000000 \n20 0.020000 0.000000 0.000000 \n21 0.000000 0.000000 0.000000 \n22 0.000000 0.000000 0.000000 \n23 0.000000 0.000000 0.000000 \n24 0.000000 0.010000 0.010000 \n25 0.000000 0.000000 0.066667 \n26 0.010000 0.000000 0.000000 \n27 0.000000 0.000000 0.000000 \n28 0.010526 0.000000 0.000000 \n29 0.000000 0.000000 0.000000 \n30 0.000000 0.000000 0.000000 \n31 0.025000 0.000000 0.000000 \n32 0.045455 0.000000 0.000000 \n33 0.000000 0.000000 0.000000 \n34 0.000000 0.000000 0.000000 \n35 0.000000 0.000000 0.000000 \n36 0.010000 0.000000 0.000000 \n37 0.018868 0.000000 0.037736 \n38 0.020000 0.000000 0.000000 \n\n Wine Bar Women's Store \n0 0.000000 0.00 \n1 0.000000 0.00 \n2 0.012048 0.00 \n3 0.011494 0.00 \n4 0.000000 0.00 \n5 0.000000 0.00 \n6 0.000000 0.00 \n7 0.000000 0.00 \n8 0.010000 0.00 \n9 0.000000 0.00 \n10 0.010000 0.00 \n11 0.000000 0.00 \n12 0.000000 0.00 \n13 0.000000 0.00 \n14 0.000000 0.00 \n15 0.000000 0.00 \n16 0.000000 0.00 \n17 0.000000 0.00 \n18 0.000000 0.00 \n19 0.000000 0.00 \n20 0.010000 0.01 \n21 0.000000 0.00 \n22 0.000000 0.00 \n23 0.000000 0.00 \n24 0.010000 0.00 \n25 0.000000 0.00 \n26 0.010000 0.00 \n27 0.000000 0.00 \n28 0.000000 0.00 \n29 0.023810 0.00 \n30 0.000000 0.00 \n31 0.000000 0.00 \n32 0.000000 0.00 \n33 0.000000 0.00 \n34 0.000000 0.00 \n35 0.000000 0.00 \n36 0.010000 0.00 \n37 0.018868 0.00 \n38 0.010000 0.00 \n\n[39 rows x 230 columns]", "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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
NeighborhoodYoga StudioAfghan RestaurantAirportAirport Food CourtAirport GateAirport LoungeAirport ServiceAirport TerminalAmerican Restaurant...TheaterTheme RestaurantToy / Game StoreTrailTrain StationVegetarian / Vegan RestaurantVideo Game StoreVietnamese RestaurantWine BarWomen's Store
0Berczy Park0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0178570.0000000.0000000.0000000.00
1Business Reply Mail Processing Centre 969 Eastern0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
2Central Bay Street0.0120480.0000000.00000.00000.00000.0000.0000.0000.012048...0.0000000.0000000.000000.000000.000.0120480.0000000.0000000.0120480.00
3Chinatown, Kensington Market, Grange Park0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0459770.0000000.0689660.0114940.00
4Christie0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
5Church and Wellesley0.0121950.0121950.00000.00000.00000.0000.0000.0000.012195...0.0121950.0121950.000000.000000.000.0000000.0000000.0000000.0000000.00
6Davisville0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.031250.000000.000.0000000.0000000.0000000.0000000.00
7Davisville North0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
8Design Exchange, Toronto Dominion Centre0.0000000.0000000.00000.00000.00000.0000.0000.0000.020000...0.0100000.0000000.000000.000000.010.0100000.0000000.0000000.0100000.00
9Dovercourt Village, Dufferin0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
10First Canadian Place, Underground city0.0000000.0000000.00000.00000.00000.0000.0000.0000.020000...0.0100000.0000000.000000.000000.010.0100000.0000000.0000000.0100000.00
11Forest Hill West, Forest Hill North0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.250000.000.0000000.0000000.0000000.0000000.00
12Harbord, University of Toronto0.0270270.0000000.00000.00000.00000.0000.0000.0000.000000...0.0270270.0000000.000000.000000.000.0000000.0270270.0000000.0000000.00
13Harbourfront0.0212770.0000000.00000.00000.00000.0000.0000.0000.000000...0.0212770.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
14Harbourfront West, CN Tower, Island airport, R...0.0000000.0000000.06250.06250.06250.1250.1250.1250.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
15Lawrence Park0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
16North Toronto West0.0476190.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
17Parkdale Village, Brockton, Exhibition Place0.0434780.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
18Parkdale, Roncesvalles0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
19Queen's Park0.0256410.0000000.00000.00000.00000.0000.0000.0000.000000...0.0256410.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
20Richmond, Adelaide, King0.0000000.0000000.00000.00000.00000.0000.0000.0000.020000...0.0100000.0000000.000000.000000.000.0200000.0000000.0000000.0100000.01
21Riverdale, The Danforth West0.0238100.0000000.00000.00000.00000.0000.0000.0000.023810...0.0000000.0000000.000000.023810.000.0000000.0000000.0000000.0000000.00
22Rosedale0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.250000.000.0000000.0000000.0000000.0000000.00
23Roselawn0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
24Ryerson, Garden District0.0000000.0000000.00000.00000.00000.0000.0000.0000.010000...0.0200000.0000000.010000.000000.000.0000000.0100000.0100000.0100000.00
25South Hill, Summerhill West, Rathnelly, Forest...0.0000000.0000000.00000.00000.00000.0000.0000.0000.066667...0.0000000.0000000.000000.000000.000.0000000.0000000.0666670.0000000.00
26St. James Town0.0000000.0000000.00000.00000.00000.0000.0000.0000.030000...0.0100000.0000000.000000.000000.000.0100000.0000000.0000000.0100000.00
27St. James Town, Cabbagetown0.0000000.0000000.00000.00000.00000.0000.0000.0000.021277...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
28Stn A PO Boxes 25 The Esplanade0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0105260.0000000.0000000.0000000.00
29Studio District0.0238100.0000000.00000.00000.00000.0000.0000.0000.047619...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0238100.00
30Summerhill East, Moore Park0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
31Swansea, Runnymede0.0250000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0250000.0000000.0000000.0000000.00
32The Annex, North Midtown, Yorkville0.0000000.0000000.00000.00000.00000.0000.0000.0000.045455...0.0000000.0000000.000000.000000.000.0454550.0000000.0000000.0000000.00
33The Beaches0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.200000.000.0000000.0000000.0000000.0000000.00
34The Beaches West, India Bazaar0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
35The Junction South, High Park0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0000000.0000000.000000.000000.000.0000000.0000000.0000000.0000000.00
36Toronto Islands, Harbourfront East, Union Station0.0000000.0000000.00000.00000.00000.0000.0000.0000.000000...0.0100000.0000000.000000.000000.010.0100000.0000000.0000000.0100000.00
37Trinity, Little Portugal0.0188680.0000000.00000.00000.00000.0000.0000.0000.000000...0.0188680.0000000.000000.000000.000.0188680.0000000.0377360.0188680.00
38Victoria Hotel, Commerce Court0.0000000.0000000.00000.00000.00000.0000.0000.0000.030000...0.0000000.0000000.000000.000000.000.0200000.0000000.0000000.0100000.00
\n

39 rows \u00d7 230 columns

\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "Toronto_grouped.shape", "execution_count": 32, "outputs": [{"output_type": "execute_result", "execution_count": 32, "data": {"text/plain": "(39, 230)"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "### Let's print each neighborhood along with the top 5 most common venues"}, {"metadata": {}, "cell_type": "code", "source": "num_top_venues = 5\n\nfor hood in Toronto_grouped['Neighborhood']:\n print(\"----\"+hood+\"----\")\n temp = Toronto_grouped[Toronto_grouped['Neighborhood'] == hood].T.reset_index()\n temp.columns = ['venue','freq']\n temp = temp.iloc[1:]\n temp['freq'] = temp['freq'].astype(float)\n temp = temp.round({'freq': 2})\n print(temp.sort_values('freq', ascending=False).reset_index(drop=True).head(num_top_venues))\n print('\\n')", "execution_count": 33, "outputs": [{"output_type": "stream", "text": "----Berczy Park----\n venue freq\n0 Coffee Shop 0.09\n1 Cocktail Bar 0.05\n2 Caf\u00e9 0.04\n3 Steakhouse 0.04\n4 Beer Bar 0.04\n\n\n----Business Reply Mail Processing Centre 969 Eastern----\n venue freq\n0 Pizza Place 0.06\n1 Auto Workshop 0.06\n2 Comic Shop 0.06\n3 Restaurant 0.06\n4 Farmers Market 0.06\n\n\n----Central Bay Street----\n venue freq\n0 Coffee Shop 0.16\n1 Caf\u00e9 0.05\n2 Ice Cream Shop 0.05\n3 Italian Restaurant 0.05\n4 Sandwich Place 0.04\n\n\n----Chinatown, Kensington Market, Grange Park----\n venue freq\n0 Caf\u00e9 0.07\n1 Vietnamese Restaurant 0.07\n2 Chinese Restaurant 0.06\n3 Bar 0.06\n4 Vegetarian / Vegan Restaurant 0.05\n\n\n----Christie----\n venue freq\n0 Grocery Store 0.21\n1 Caf\u00e9 0.16\n2 Park 0.11\n3 Baby Store 0.05\n4 Nightclub 0.05\n\n\n----Church and Wellesley----\n venue freq\n0 Coffee Shop 0.07\n1 Gay Bar 0.05\n2 Sushi Restaurant 0.05\n3 Japanese Restaurant 0.05\n4 Restaurant 0.04\n\n\n----Davisville----\n venue freq\n0 Pizza Place 0.09\n1 Sandwich Place 0.09\n2 Dessert Shop 0.09\n3 Italian Restaurant 0.06\n4 Sushi Restaurant 0.06\n\n\n----Davisville North----\n venue freq\n0 Gym 0.12\n1 Hotel 0.12\n2 Dance Studio 0.12\n3 Department Store 0.12\n4 Sandwich Place 0.12\n\n\n----Design Exchange, Toronto Dominion Centre----\n venue freq\n0 Coffee Shop 0.12\n1 Caf\u00e9 0.08\n2 Hotel 0.07\n3 Restaurant 0.04\n4 Steakhouse 0.04\n\n\n----Dovercourt Village, Dufferin----\n venue freq\n0 Pharmacy 0.12\n1 Bakery 0.12\n2 Park 0.06\n3 Music Venue 0.06\n4 Recording Studio 0.06\n\n\n----First Canadian Place, Underground city----\n venue freq\n0 Coffee Shop 0.12\n1 Caf\u00e9 0.07\n2 Restaurant 0.04\n3 Steakhouse 0.04\n4 Hotel 0.03\n\n\n----Forest Hill West, Forest Hill North----\n venue freq\n0 Jewelry Store 0.25\n1 Trail 0.25\n2 Mexican Restaurant 0.25\n3 Sushi Restaurant 0.25\n4 Yoga Studio 0.00\n\n\n----Harbord, University of Toronto----\n venue freq\n0 Caf\u00e9 0.14\n1 Bar 0.05\n2 Bookstore 0.05\n3 Japanese Restaurant 0.05\n4 Bakery 0.05\n\n\n----Harbourfront----\n venue freq\n0 Coffee Shop 0.17\n1 Park 0.06\n2 Bakery 0.06\n3 Pub 0.06\n4 Caf\u00e9 0.06\n\n\n----Harbourfront West, CN Tower, Island airport, Railway Lands, Bathurst Quay, South Niagara, King and Spadina----\n venue freq\n0 Airport Lounge 0.12\n1 Airport Service 0.12\n2 Airport Terminal 0.12\n3 Harbor / Marina 0.06\n4 Bar 0.06\n\n\n----Lawrence Park----\n venue freq\n0 Park 0.33\n1 Bus Line 0.33\n2 Swim School 0.33\n3 Yoga Studio 0.00\n4 Monument / Landmark 0.00\n\n\n----North Toronto West----\n venue freq\n0 Clothing Store 0.19\n1 Coffee Shop 0.10\n2 Yoga Studio 0.05\n3 Chinese Restaurant 0.05\n4 Park 0.05\n\n\n----Parkdale Village, Brockton, Exhibition Place----\n venue freq\n0 Coffee Shop 0.09\n1 Nightclub 0.09\n2 Caf\u00e9 0.09\n3 Breakfast Spot 0.09\n4 Yoga Studio 0.04\n\n\n----Parkdale, Roncesvalles----\n venue freq\n0 Breakfast Spot 0.14\n1 Gift Shop 0.14\n2 Coffee Shop 0.07\n3 Eastern European Restaurant 0.07\n4 Movie Theater 0.07\n\n\n----Queen's Park----\n venue freq\n0 Coffee Shop 0.23\n1 Park 0.05\n2 Gym 0.05\n3 Creperie 0.03\n4 Burrito Place 0.03\n\n\n----Richmond, Adelaide, King----\n venue freq\n0 Coffee Shop 0.07\n1 Caf\u00e9 0.04\n2 Steakhouse 0.04\n3 Bakery 0.03\n4 Thai Restaurant 0.03\n\n\n----Riverdale, The Danforth West----\n venue freq\n0 Greek Restaurant 0.21\n1 Coffee Shop 0.10\n2 Italian Restaurant 0.07\n3 Restaurant 0.05\n4 Ice Cream Shop 0.05\n\n\n----Rosedale----\n venue freq\n0 Park 0.50\n1 Playground 0.25\n2 Trail 0.25\n3 Yoga Studio 0.00\n4 Movie Theater 0.00\n\n\n----Roselawn----\n venue freq\n0 Home Service 0.33\n1 Garden 0.33\n2 Ice Cream Shop 0.33\n3 Yoga Studio 0.00\n4 Movie Theater 0.00\n\n\n----Ryerson, Garden District----\n venue freq\n0 Coffee Shop 0.09\n1 Clothing Store 0.08\n2 Cosmetics Shop 0.03\n3 Japanese Restaurant 0.03\n4 Caf\u00e9 0.03\n\n\n----South Hill, Summerhill West, Rathnelly, Forest Hill SE, Deer Park----\n venue freq\n0 Pub 0.13\n1 Coffee Shop 0.13\n2 Pizza Place 0.07\n3 Fried Chicken Joint 0.07\n4 Sushi Restaurant 0.07\n\n\n----St. James Town----\n venue freq\n0 Coffee Shop 0.08\n1 Caf\u00e9 0.06\n2 Restaurant 0.05\n3 American Restaurant 0.03\n4 Bakery 0.03\n\n\n----St. James Town, Cabbagetown----\n venue freq\n0 Coffee Shop 0.11\n1 Market 0.04\n2 Italian Restaurant 0.04\n3 Pizza Place 0.04\n4 Pub 0.04\n\n\n----Stn A PO Boxes 25 The Esplanade----\n venue freq\n0 Coffee Shop 0.14\n1 Caf\u00e9 0.04\n2 Hotel 0.03\n3 Restaurant 0.03\n4 Italian Restaurant 0.03\n\n\n----Studio District----\n venue freq\n0 Caf\u00e9 0.10\n1 Coffee Shop 0.07\n2 Brewery 0.05\n3 Bakery 0.05\n4 American Restaurant 0.05\n\n\n----Summerhill East, Moore Park----\n venue freq\n0 Tennis Court 1.0\n1 Yoga Studio 0.0\n2 Movie Theater 0.0\n3 Liquor Store 0.0\n4 Lounge 0.0\n\n\n----Swansea, Runnymede----\n venue freq\n0 Pizza Place 0.08\n1 Caf\u00e9 0.08\n2 Coffee Shop 0.08\n3 Italian Restaurant 0.05\n4 Sushi Restaurant 0.05\n\n\n----The Annex, North Midtown, Yorkville----\n venue freq\n0 Sandwich Place 0.14\n1 Caf\u00e9 0.14\n2 Coffee Shop 0.09\n3 Indian Restaurant 0.05\n4 BBQ Joint 0.05\n\n\n----The Beaches----\n venue freq\n0 Asian Restaurant 0.2\n1 Health Food Store 0.2\n2 Pub 0.2\n3 Trail 0.2\n4 Yoga Studio 0.0\n\n\n----The Beaches West, India Bazaar----\n venue freq\n0 Gym 0.06\n1 Sushi Restaurant 0.06\n2 Pet Store 0.06\n3 Pizza Place 0.06\n4 Pub 0.06\n\n\n----The Junction South, High Park----\n venue freq\n0 Mexican Restaurant 0.08\n1 Caf\u00e9 0.08\n2 Bar 0.08\n3 Thai Restaurant 0.08\n4 Bakery 0.04\n\n\n----Toronto Islands, Harbourfront East, Union Station----\n venue freq\n0 Coffee Shop 0.12\n1 Aquarium 0.05\n2 Hotel 0.04\n3 Italian Restaurant 0.04\n4 Caf\u00e9 0.04\n\n\n----Trinity, Little Portugal----\n venue freq\n0 Bar 0.13\n1 Restaurant 0.06\n2 Asian Restaurant 0.06\n3 Coffee Shop 0.06\n4 Caf\u00e9 0.04\n\n\n----Victoria Hotel, Commerce Court----\n venue freq\n0 Coffee Shop 0.12\n1 Caf\u00e9 0.07\n2 Hotel 0.05\n3 Restaurant 0.05\n4 Italian Restaurant 0.03\n\n\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "markdown", "source": "### Let's put that into a pandas dataframe\nFirst, let's write a function to sort the venues in descending order."}, {"metadata": {}, "cell_type": "code", "source": "def return_most_common_venues(row, num_top_venues):\n row_categories = row.iloc[1:]\n row_categories_sorted = row_categories.sort_values(ascending=False)\n \n return row_categories_sorted.index.values[0:num_top_venues]", "execution_count": 34, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "Now let's create the new dataframe and display the top 10 venues for each neighborhood."}, {"metadata": {}, "cell_type": "code", "source": "num_top_venues = 10\n\nindicators = ['st', 'nd', 'rd']\n\n# create columns according to number of top venues\ncolumns = ['Neighborhood']\nfor ind in np.arange(num_top_venues):\n try:\n columns.append('{}{} Most Common Venue'.format(ind+1, indicators[ind]))\n except:\n columns.append('{}th Most Common Venue'.format(ind+1))\n\n# create a new dataframe\nneighborhoods_venues_sorted = pd.DataFrame(columns=columns)\nneighborhoods_venues_sorted['Neighborhood'] = Toronto_grouped['Neighborhood']\n\nfor ind in np.arange(Toronto_grouped.shape[0]):\n neighborhoods_venues_sorted.iloc[ind, 1:] = return_most_common_venues(Toronto_grouped.iloc[ind, :], num_top_venues)\n\nneighborhoods_venues_sorted.head()", "execution_count": 35, "outputs": [{"output_type": "execute_result", "execution_count": 35, "data": {"text/plain": " Neighborhood 1st Most Common Venue \\\n0 Berczy Park Coffee Shop \n1 Business Reply Mail Processing Centre 969 Eastern Park \n2 Central Bay Street Coffee Shop \n3 Chinatown, Kensington Market, Grange Park Caf\u00e9 \n4 Christie Grocery Store \n\n 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n0 Cocktail Bar Bakery Cheese Shop \n1 Auto Workshop Comic Shop Pizza Place \n2 Italian Restaurant Caf\u00e9 Ice Cream Shop \n3 Vietnamese Restaurant Bar Chinese Restaurant \n4 Caf\u00e9 Park Restaurant \n\n 5th Most Common Venue 6th Most Common Venue 7th Most Common Venue \\\n0 Beer Bar Seafood Restaurant Farmers Market \n1 Burrito Place Restaurant Brewery \n2 Juice Bar Sandwich Place Burger Joint \n3 Coffee Shop Vegetarian / Vegan Restaurant Dumpling Restaurant \n4 Candy Store Nightclub Baby Store \n\n 8th Most Common Venue 9th Most Common Venue 10th Most Common Venue \n0 Steakhouse Caf\u00e9 Gourmet Shop \n1 Light Rail Station Smoke Shop Farmers Market \n2 Japanese Restaurant Salad Place Department Store \n3 Mexican Restaurant Cocktail Bar Burger Joint \n4 Gas Station Coffee Shop Bank ", "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
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 BarBakeryCheese ShopBeer BarSeafood RestaurantFarmers MarketSteakhouseCaf\u00e9Gourmet Shop
1Business Reply Mail Processing Centre 969 EasternParkAuto WorkshopComic ShopPizza PlaceBurrito PlaceRestaurantBreweryLight Rail StationSmoke ShopFarmers Market
2Central Bay StreetCoffee ShopItalian RestaurantCaf\u00e9Ice Cream ShopJuice BarSandwich PlaceBurger JointJapanese RestaurantSalad PlaceDepartment Store
3Chinatown, Kensington Market, Grange ParkCaf\u00e9Vietnamese RestaurantBarChinese RestaurantCoffee ShopVegetarian / Vegan RestaurantDumpling RestaurantMexican RestaurantCocktail BarBurger Joint
4ChristieGrocery StoreCaf\u00e9ParkRestaurantCandy StoreNightclubBaby StoreGas StationCoffee ShopBank
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "## Cluster Neighborhoods"}, {"metadata": {}, "cell_type": "markdown", "source": "Run k-means to cluster the neighborhood into 5 clusters."}, {"metadata": {}, "cell_type": "code", "source": "from sklearn.cluster import KMeans #importing KMeans\n\n# set number of clusters\nkclusters = 5\n\nToronto_grouped_clustering = Toronto_grouped.drop('Neighborhood', 1)\n\n# run k-means clustering\nkmeans = KMeans(n_clusters=kclusters, random_state=0).fit(Toronto_grouped_clustering)\n\n# check cluster labels generated for each row in the dataframe\nkmeans.labels_[0:10] ", "execution_count": 36, "outputs": [{"output_type": "execute_result", "execution_count": 36, "data": {"text/plain": "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Let's create a new dataframe that includes the cluster as well as the top 10 venues for each neighborhood."}, {"metadata": {}, "cell_type": "code", "source": "# add clustering labels\nneighborhoods_venues_sorted.insert(0, 'Cluster Labels', kmeans.labels_)\n\nToronto = New_Toronto_df\n\nToronto = Toronto.join(neighborhoods_venues_sorted.set_index('Neighborhood'), on='Neighborhood')\n\nToronto.head() ", "execution_count": 37, "outputs": [{"output_type": "execute_result", "execution_count": 37, "data": {"text/plain": " PostalCode Borough Neighborhood Latitude \\\n0 M4E East Toronto The Beaches 43.676357 \n1 M4K East Toronto Riverdale, The Danforth West 43.679557 \n2 M4L East Toronto The Beaches West, India Bazaar 43.668999 \n3 M4M East Toronto Studio District 43.659526 \n4 M4N Central Toronto Lawrence Park 43.728020 \n\n Longitude Cluster Labels 1st Most Common Venue 2nd Most Common Venue \\\n0 -79.293031 0 Asian Restaurant Health Food Store \n1 -79.352188 0 Greek Restaurant Coffee Shop \n2 -79.315572 0 Sandwich Place Italian Restaurant \n3 -79.340923 0 Caf\u00e9 Coffee Shop \n4 -79.388790 4 Park Bus Line \n\n 3rd Most Common Venue 4th Most Common Venue 5th Most Common Venue \\\n0 Pub Trail Dessert Shop \n1 Italian Restaurant Ice Cream Shop Furniture / Home Store \n2 Steakhouse Fast Food Restaurant Sushi Restaurant \n3 Gastropub Brewery Bakery \n4 Swim School Event Space Ethiopian Restaurant \n\n 6th Most Common Venue 7th Most Common Venue 8th Most Common Venue \\\n0 Dim Sum Restaurant Diner Discount Store \n1 Restaurant Bookstore Grocery Store \n2 Ice Cream Shop Liquor Store Burrito Place \n3 Italian Restaurant American Restaurant Comfort Food Restaurant \n4 Electronics Store Eastern European Restaurant Dumpling Restaurant \n\n 9th Most Common Venue 10th Most Common Venue \n0 Dog Run Doner Restaurant \n1 Pub Pizza Place \n2 Burger Joint Fish & Chips Shop \n3 Sandwich Place Cheese Shop \n4 Donut Shop Doner 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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PostalCodeBoroughNeighborhoodLatitudeLongitudeCluster 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
0M4EEast TorontoThe Beaches43.676357-79.2930310Asian RestaurantHealth Food StorePubTrailDessert ShopDim Sum RestaurantDinerDiscount StoreDog RunDoner Restaurant
1M4KEast TorontoRiverdale, The Danforth West43.679557-79.3521880Greek RestaurantCoffee ShopItalian RestaurantIce Cream ShopFurniture / Home StoreRestaurantBookstoreGrocery StorePubPizza Place
2M4LEast TorontoThe Beaches West, India Bazaar43.668999-79.3155720Sandwich PlaceItalian RestaurantSteakhouseFast Food RestaurantSushi RestaurantIce Cream ShopLiquor StoreBurrito PlaceBurger JointFish & Chips Shop
3M4MEast TorontoStudio District43.659526-79.3409230Caf\u00e9Coffee ShopGastropubBreweryBakeryItalian RestaurantAmerican RestaurantComfort Food RestaurantSandwich PlaceCheese Shop
4M4NCentral TorontoLawrence Park43.728020-79.3887904ParkBus LineSwim SchoolEvent SpaceEthiopian RestaurantElectronics StoreEastern European RestaurantDumpling RestaurantDonut ShopDoner Restaurant
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "#### Finally, let's visualize the resulting clusters"}, {"metadata": {"scrolled": true}, "cell_type": "code", "source": "# Matplotlib and associated plotting modules\nimport matplotlib.cm as cm\nimport matplotlib.colors as colors\n\n# create map\nmap_clusters = folium.Map(location=[To_latitude, To_longitude], zoom_start=11)\n\n# set color scheme for the clusters\nx = np.arange(kclusters)\nys = [i + x + (i*x)**2 for i in range(kclusters)]\ncolors_array = cm.rainbow(np.linspace(0, 1, len(ys)))\nrainbow = [colors.rgb2hex(i) for i in colors_array]\n\n# add markers to the map\nmarkers_colors = []\nfor lat, lon, poi, cluster in zip(Toronto['Latitude'], Toronto['Longitude'], Toronto['Neighborhood'], Toronto['Cluster Labels']):\n label = folium.Popup(str(poi) + ' Cluster ' + str(cluster), parse_html=True)\n folium.CircleMarker(\n [lat, lon],\n radius=5,\n popup=label,\n color=rainbow[cluster-1],\n fill=True,\n fill_color=rainbow[cluster-1],\n fill_opacity=0.7).add_to(map_clusters)\n \nmap_clusters", "execution_count": 38, "outputs": [{"output_type": "execute_result", "execution_count": 38, "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": " ## Examining Clusters"}, {"metadata": {}, "cell_type": "markdown", "source": "Now, I can examine each cluster and determine the discriminating venue categories that distinguish each cluster. Based on the defining categories,I can then assign a name to each cluster"}, {"metadata": {}, "cell_type": "code", "source": "Toronto.loc[Toronto['Cluster Labels'] == 0, Toronto.columns[[1] + list(range(5, Toronto.shape[1]))]]", "execution_count": 39, "outputs": [{"output_type": "execute_result", "execution_count": 39, "data": {"text/plain": " Borough Cluster Labels 1st Most Common Venue \\\n0 East Toronto 0 Asian Restaurant \n1 East Toronto 0 Greek Restaurant \n2 East Toronto 0 Sandwich Place \n3 East Toronto 0 Caf\u00e9 \n5 Central Toronto 0 Hotel \n6 Central Toronto 0 Clothing Store \n7 Central Toronto 0 Sandwich Place \n9 Central Toronto 0 Coffee Shop \n11 Downtown Toronto 0 Coffee Shop \n12 Downtown Toronto 0 Coffee Shop \n13 Downtown Toronto 0 Coffee Shop \n14 Downtown Toronto 0 Coffee Shop \n15 Downtown Toronto 0 Coffee Shop \n16 Downtown Toronto 0 Coffee Shop \n17 Downtown Toronto 0 Coffee Shop \n18 Downtown Toronto 0 Coffee Shop \n19 Downtown Toronto 0 Coffee Shop \n20 Downtown Toronto 0 Coffee Shop \n21 Downtown Toronto 0 Coffee Shop \n24 Central Toronto 0 Sandwich Place \n25 Downtown Toronto 0 Caf\u00e9 \n26 Downtown Toronto 0 Caf\u00e9 \n27 Downtown Toronto 0 Airport Terminal \n28 Downtown Toronto 0 Coffee Shop \n29 Downtown Toronto 0 Coffee Shop \n30 Downtown Toronto 0 Grocery Store \n31 West Toronto 0 Pharmacy \n32 West Toronto 0 Bar \n33 West Toronto 0 Coffee Shop \n34 West Toronto 0 Mexican Restaurant \n35 West Toronto 0 Gift Shop \n36 West Toronto 0 Caf\u00e9 \n37 Downtown Toronto 0 Coffee Shop \n38 East Toronto 0 Park \n\n 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n0 Health Food Store Pub Trail \n1 Coffee Shop Italian Restaurant Ice Cream Shop \n2 Italian Restaurant Steakhouse Fast Food Restaurant \n3 Coffee Shop Gastropub Brewery \n5 Park Gym Breakfast Spot \n6 Coffee Shop Yoga Studio Bagel Shop \n7 Dessert Shop Pizza Place Coffee Shop \n9 Pub Sushi Restaurant Pizza Place \n11 Park Pub Restaurant \n12 Sushi Restaurant Gay Bar Japanese Restaurant \n13 Bakery Park Pub \n14 Clothing Store Japanese Restaurant Caf\u00e9 \n15 Caf\u00e9 Restaurant American Restaurant \n16 Cocktail Bar Bakery Cheese Shop \n17 Italian Restaurant Caf\u00e9 Ice Cream Shop \n18 Caf\u00e9 Steakhouse Cosmetics Shop \n19 Aquarium Caf\u00e9 Italian Restaurant \n20 Caf\u00e9 Hotel Restaurant \n21 Caf\u00e9 Restaurant Hotel \n24 Caf\u00e9 Coffee Shop Park \n25 Bakery Japanese Restaurant Sandwich Place \n26 Vietnamese Restaurant Bar Chinese Restaurant \n27 Airport Lounge Airport Service Plane \n28 Caf\u00e9 Hotel Italian Restaurant \n29 Caf\u00e9 Steakhouse Restaurant \n30 Caf\u00e9 Park Restaurant \n31 Bakery Park Supermarket \n32 Coffee Shop Asian Restaurant Restaurant \n33 Breakfast Spot Caf\u00e9 Nightclub \n34 Caf\u00e9 Thai Restaurant Bar \n35 Breakfast Spot Cuban Restaurant Eastern European Restaurant \n36 Pizza Place Coffee Shop Italian Restaurant \n37 Gym Park Diner \n38 Auto Workshop Comic Shop Pizza Place \n\n 5th Most Common Venue 6th Most Common Venue \\\n0 Dessert Shop Dim Sum Restaurant \n1 Furniture / Home Store Restaurant \n2 Sushi Restaurant Ice Cream Shop \n3 Bakery Italian Restaurant \n5 Dance Studio Sandwich Place \n6 Fast Food Restaurant Diner \n7 Italian Restaurant Gym \n9 Sports Bar Supermarket \n11 Italian Restaurant Caf\u00e9 \n12 Restaurant Hotel \n13 Caf\u00e9 Breakfast Spot \n14 Cosmetics Shop Diner \n15 Breakfast Spot Cocktail Bar \n16 Beer Bar Seafood Restaurant \n17 Juice Bar Sandwich Place \n18 Bakery Breakfast Spot \n19 Hotel Scenic Lookout \n20 Steakhouse Deli / Bodega \n21 Gastropub Steakhouse \n24 History Museum Liquor Store \n25 Restaurant Bookstore \n26 Coffee Shop Vegetarian / Vegan Restaurant \n27 Rental Car Location Boat or Ferry \n28 Beer Bar Seafood Restaurant \n29 Deli / Bodega Gastropub \n30 Candy Store Nightclub \n31 Bar Middle Eastern Restaurant \n32 Vietnamese Restaurant Pizza Place \n33 Pet Store Bar \n34 Park Fried Chicken Joint \n35 Italian Restaurant Bar \n36 Sushi Restaurant Bookstore \n37 Beer Bar Seafood Restaurant \n38 Burrito Place Restaurant \n\n 7th Most Common Venue 8th Most Common Venue 9th Most Common Venue \\\n0 Diner Discount Store Dog Run \n1 Bookstore Grocery Store Pub \n2 Liquor Store Burrito Place Burger Joint \n3 American Restaurant Comfort Food Restaurant Sandwich Place \n5 Department Store Food & Drink Shop Diner \n6 Dessert Shop Mexican Restaurant Chinese Restaurant \n7 Caf\u00e9 Sushi Restaurant Pharmacy \n9 Fried Chicken Joint Health & Beauty Service American Restaurant \n11 Market Bakery Pizza Place \n12 Fast Food Restaurant Gastropub Burger Joint \n13 Mexican Restaurant Restaurant Dessert Shop \n14 Fast Food Restaurant Electronics Store Bubble Tea Shop \n15 Beer Bar Cosmetics Shop Bakery \n16 Farmers Market Steakhouse Caf\u00e9 \n17 Burger Joint Japanese Restaurant Salad Place \n18 Burger Joint Asian Restaurant Thai Restaurant \n19 Brewery Sporting Goods Shop Restaurant \n20 Seafood Restaurant Gastropub Bar \n21 Bakery Italian Restaurant Gym \n24 Burger Joint Indian Restaurant Pub \n25 Bar College Arts Building Coffee Shop \n26 Dumpling Restaurant Mexican Restaurant Cocktail Bar \n27 Harbor / Marina Boutique Bar \n28 Restaurant Cocktail Bar Japanese Restaurant \n29 Bar Asian Restaurant Gym \n30 Baby Store Gas Station Coffee Shop \n31 Caf\u00e9 Recording Studio Fast Food Restaurant \n32 Men's Store Caf\u00e9 Greek Restaurant \n33 Burrito Place Restaurant Climbing Gym \n34 Music Venue Diner Cajun / Creole Restaurant \n35 Dog Run Restaurant Movie Theater \n36 Electronics Store Burrito Place Pub \n37 Sandwich Place Salad Place Juice Bar \n38 Brewery Light Rail Station Smoke Shop \n\n 10th Most Common Venue \n0 Doner Restaurant \n1 Pizza Place \n2 Fish & Chips Shop \n3 Cheese Shop \n5 Dessert Shop \n6 Caf\u00e9 \n7 Brewery \n9 Restaurant \n11 Beer Store \n12 Gym \n13 Bank \n14 Bakery \n15 Italian Restaurant \n16 Gourmet Shop \n17 Department Store \n18 Bar \n19 Fried Chicken Joint \n20 Japanese Restaurant \n21 American Restaurant \n24 Flower Shop \n25 Chinese Restaurant \n26 Burger Joint \n27 Airport Gate \n28 Art Gallery \n29 Seafood Restaurant \n30 Bank \n31 Gym / Fitness Center \n32 Juice Bar \n33 Performing Arts Venue \n34 Bookstore \n35 Dessert Shop \n36 Post Office \n37 Restaurant \n38 Farmers Market ", "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 \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
BoroughCluster 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
0East Toronto0Asian RestaurantHealth Food StorePubTrailDessert ShopDim Sum RestaurantDinerDiscount StoreDog RunDoner Restaurant
1East Toronto0Greek RestaurantCoffee ShopItalian RestaurantIce Cream ShopFurniture / Home StoreRestaurantBookstoreGrocery StorePubPizza Place
2East Toronto0Sandwich PlaceItalian RestaurantSteakhouseFast Food RestaurantSushi RestaurantIce Cream ShopLiquor StoreBurrito PlaceBurger JointFish & Chips Shop
3East Toronto0Caf\u00e9Coffee ShopGastropubBreweryBakeryItalian RestaurantAmerican RestaurantComfort Food RestaurantSandwich PlaceCheese Shop
5Central Toronto0HotelParkGymBreakfast SpotDance StudioSandwich PlaceDepartment StoreFood & Drink ShopDinerDessert Shop
6Central Toronto0Clothing StoreCoffee ShopYoga StudioBagel ShopFast Food RestaurantDinerDessert ShopMexican RestaurantChinese RestaurantCaf\u00e9
7Central Toronto0Sandwich PlaceDessert ShopPizza PlaceCoffee ShopItalian RestaurantGymCaf\u00e9Sushi RestaurantPharmacyBrewery
9Central Toronto0Coffee ShopPubSushi RestaurantPizza PlaceSports BarSupermarketFried Chicken JointHealth & Beauty ServiceAmerican RestaurantRestaurant
11Downtown Toronto0Coffee ShopParkPubRestaurantItalian RestaurantCaf\u00e9MarketBakeryPizza PlaceBeer Store
12Downtown Toronto0Coffee ShopSushi RestaurantGay BarJapanese RestaurantRestaurantHotelFast Food RestaurantGastropubBurger JointGym
13Downtown Toronto0Coffee ShopBakeryParkPubCaf\u00e9Breakfast SpotMexican RestaurantRestaurantDessert ShopBank
14Downtown Toronto0Coffee ShopClothing StoreJapanese RestaurantCaf\u00e9Cosmetics ShopDinerFast Food RestaurantElectronics StoreBubble Tea ShopBakery
15Downtown Toronto0Coffee ShopCaf\u00e9RestaurantAmerican RestaurantBreakfast SpotCocktail BarBeer BarCosmetics ShopBakeryItalian Restaurant
16Downtown Toronto0Coffee ShopCocktail BarBakeryCheese ShopBeer BarSeafood RestaurantFarmers MarketSteakhouseCaf\u00e9Gourmet Shop
17Downtown Toronto0Coffee ShopItalian RestaurantCaf\u00e9Ice Cream ShopJuice BarSandwich PlaceBurger JointJapanese RestaurantSalad PlaceDepartment Store
18Downtown Toronto0Coffee ShopCaf\u00e9SteakhouseCosmetics ShopBakeryBreakfast SpotBurger JointAsian RestaurantThai RestaurantBar
19Downtown Toronto0Coffee ShopAquariumCaf\u00e9Italian RestaurantHotelScenic LookoutBrewerySporting Goods ShopRestaurantFried Chicken Joint
20Downtown Toronto0Coffee ShopCaf\u00e9HotelRestaurantSteakhouseDeli / BodegaSeafood RestaurantGastropubBarJapanese Restaurant
21Downtown Toronto0Coffee ShopCaf\u00e9RestaurantHotelGastropubSteakhouseBakeryItalian RestaurantGymAmerican Restaurant
24Central Toronto0Sandwich PlaceCaf\u00e9Coffee ShopParkHistory MuseumLiquor StoreBurger JointIndian RestaurantPubFlower Shop
25Downtown Toronto0Caf\u00e9BakeryJapanese RestaurantSandwich PlaceRestaurantBookstoreBarCollege Arts BuildingCoffee ShopChinese Restaurant
26Downtown Toronto0Caf\u00e9Vietnamese RestaurantBarChinese RestaurantCoffee ShopVegetarian / Vegan RestaurantDumpling RestaurantMexican RestaurantCocktail BarBurger Joint
27Downtown Toronto0Airport TerminalAirport LoungeAirport ServicePlaneRental Car LocationBoat or FerryHarbor / MarinaBoutiqueBarAirport Gate
28Downtown Toronto0Coffee ShopCaf\u00e9HotelItalian RestaurantBeer BarSeafood RestaurantRestaurantCocktail BarJapanese RestaurantArt Gallery
29Downtown Toronto0Coffee ShopCaf\u00e9SteakhouseRestaurantDeli / BodegaGastropubBarAsian RestaurantGymSeafood Restaurant
30Downtown Toronto0Grocery StoreCaf\u00e9ParkRestaurantCandy StoreNightclubBaby StoreGas StationCoffee ShopBank
31West Toronto0PharmacyBakeryParkSupermarketBarMiddle Eastern RestaurantCaf\u00e9Recording StudioFast Food RestaurantGym / Fitness Center
32West Toronto0BarCoffee ShopAsian RestaurantRestaurantVietnamese RestaurantPizza PlaceMen's StoreCaf\u00e9Greek RestaurantJuice Bar
33West Toronto0Coffee ShopBreakfast SpotCaf\u00e9NightclubPet StoreBarBurrito PlaceRestaurantClimbing GymPerforming Arts Venue
34West Toronto0Mexican RestaurantCaf\u00e9Thai RestaurantBarParkFried Chicken JointMusic VenueDinerCajun / Creole RestaurantBookstore
35West Toronto0Gift ShopBreakfast SpotCuban RestaurantEastern European RestaurantItalian RestaurantBarDog RunRestaurantMovie TheaterDessert Shop
36West Toronto0Caf\u00e9Pizza PlaceCoffee ShopItalian RestaurantSushi RestaurantBookstoreElectronics StoreBurrito PlacePubPost Office
37Downtown Toronto0Coffee ShopGymParkDinerBeer BarSeafood RestaurantSandwich PlaceSalad PlaceJuice BarRestaurant
38East Toronto0ParkAuto WorkshopComic ShopPizza PlaceBurrito PlaceRestaurantBreweryLight Rail StationSmoke ShopFarmers Market
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "In Cluster = 0 mostly all veneues related to Food and drinking services. \nName:- Food Services"}, {"metadata": {}, "cell_type": "code", "source": "Toronto.loc[Toronto['Cluster Labels'] == 1, Toronto.columns[[1] + list(range(5, Toronto.shape[1]))]]", "execution_count": 40, "outputs": [{"output_type": "execute_result", "execution_count": 40, "data": {"text/plain": " Borough Cluster Labels 1st Most Common Venue \\\n22 Central Toronto 1 Garden \n\n 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n22 Home Service Ice Cream Shop Women's Store \n\n 5th Most Common Venue 6th Most Common Venue 7th Most Common Venue \\\n22 Department Store Ethiopian Restaurant Electronics Store \n\n 8th Most Common Venue 9th Most Common Venue 10th Most Common Venue \n22 Eastern European Restaurant Dumpling Restaurant Donut Shop ", "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
BoroughCluster 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
22Central Toronto1GardenHome ServiceIce Cream ShopWomen's StoreDepartment StoreEthiopian RestaurantElectronics StoreEastern European RestaurantDumpling RestaurantDonut Shop
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Cluster = 1, Name:- Home Services"}, {"metadata": {}, "cell_type": "code", "source": "Toronto.loc[Toronto['Cluster Labels'] == 2, Toronto.columns[[1] + list(range(5, Toronto.shape[1]))]]", "execution_count": 41, "outputs": [{"output_type": "execute_result", "execution_count": 41, "data": {"text/plain": " Borough Cluster Labels 1st Most Common Venue \\\n23 Central Toronto 2 Jewelry Store \n\n 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n23 Trail Mexican Restaurant Sushi Restaurant \n\n 5th Most Common Venue 6th Most Common Venue 7th Most Common Venue \\\n23 Women's Store Department Store Electronics Store \n\n 8th Most Common Venue 9th Most Common Venue 10th Most Common Venue \n23 Eastern European Restaurant Dumpling Restaurant Donut Shop ", "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
BoroughCluster 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
23Central Toronto2Jewelry StoreTrailMexican RestaurantSushi RestaurantWomen's StoreDepartment StoreElectronics StoreEastern European RestaurantDumpling RestaurantDonut Shop
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "cluster=2 Name:- Garments Store"}, {"metadata": {}, "cell_type": "code", "source": "Toronto.loc[Toronto['Cluster Labels'] == 3, Toronto.columns[[1] + list(range(5, Toronto.shape[1]))]]", "execution_count": 42, "outputs": [{"output_type": "execute_result", "execution_count": 42, "data": {"text/plain": " Borough Cluster Labels 1st Most Common Venue \\\n8 Central Toronto 3 Tennis Court \n\n 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n8 Women's Store Deli / Bodega Ethiopian Restaurant \n\n 5th Most Common Venue 6th Most Common Venue 7th Most Common Venue \\\n8 Electronics Store Eastern European Restaurant Dumpling Restaurant \n\n 8th Most Common Venue 9th Most Common Venue 10th Most Common Venue \n8 Donut Shop Doner Restaurant Dog Run ", "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
BoroughCluster 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
8Central Toronto3Tennis CourtWomen's StoreDeli / BodegaEthiopian RestaurantElectronics StoreEastern European RestaurantDumpling RestaurantDonut ShopDoner RestaurantDog Run
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Cluster = 3 Name:- Play Grounds"}, {"metadata": {}, "cell_type": "code", "source": "Toronto.loc[Toronto['Cluster Labels'] == 4, Toronto.columns[[1] + list(range(5, Toronto.shape[1]))]]", "execution_count": 43, "outputs": [{"output_type": "execute_result", "execution_count": 43, "data": {"text/plain": " Borough Cluster Labels 1st Most Common Venue \\\n4 Central Toronto 4 Park \n10 Downtown Toronto 4 Park \n\n 2nd Most Common Venue 3rd Most Common Venue 4th Most Common Venue \\\n4 Bus Line Swim School Event Space \n10 Trail Playground Dance Studio \n\n 5th Most Common Venue 6th Most Common Venue \\\n4 Ethiopian Restaurant Electronics Store \n10 Electronics Store Eastern European Restaurant \n\n 7th Most Common Venue 8th Most Common Venue 9th Most Common Venue \\\n4 Eastern European Restaurant Dumpling Restaurant Donut Shop \n10 Dumpling Restaurant Donut Shop Doner Restaurant \n\n 10th Most Common Venue \n4 Doner Restaurant \n10 Dog Run ", "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
BoroughCluster 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
4Central Toronto4ParkBus LineSwim SchoolEvent SpaceEthiopian RestaurantElectronics StoreEastern European RestaurantDumpling RestaurantDonut ShopDoner Restaurant
10Downtown Toronto4ParkTrailPlaygroundDance StudioElectronics StoreEastern European RestaurantDumpling RestaurantDonut ShopDoner RestaurantDog Run
\n
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "markdown", "source": "Cluster = 4, Name:- Transports"}], "metadata": {"kernelspec": {"name": "python3", "display_name": "Python 3.6", "language": "python"}, "language_info": {"name": "python", "version": "3.6.9", "mimetype": "text/x-python", "codemirror_mode": {"name": "ipython", "version": 3}, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py"}}, "nbformat": 4, "nbformat_minor": 1}