<jupyter_start><jupyter_text>Data Gathering and Data Wrangling<jupyter_code># Importing Neccessary Modules
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
import requests
url = 'https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M'
html = requests.get(url).text
html
soup = BeautifulSoup(html,'html.parser')
soup
data = []
for tr in soup.find_all('tr'):
    td = tr.find_all('td')
    if(len(td) == 3):
        data.append(td)    
final = []
for i in data:
    if not 'Not assigned' == i[1].text.strip():
        temp = []
        temp.append(str(i[0].text.strip()))
        temp.append(str(i[1].text.strip()))
        temp.append(str(i[2].text.strip()))
        final.append(temp)
pc_data = pd.DataFrame(data=final,columns=['PostCode','Borough','Neighbourhood'])
pc_data = pc_data.Neighbourhood.groupby([pc_data.PostCode,pc_data.Borough]).apply(list).reset_index()
pc_data['Neighbourhood'] = pc_data['Neighbourhood'].apply(lambda x : ", ".join(x))
pc_data
pc_data.shape
pc_data.to_csv('pc_data.csv')
df = pd.read_csv('Geospatial_Coordinates.csv')
df.columns = ['PostCode', 'Latitude', 'Longitude']
pc_data = pd.merge(pc_data,df,on='PostCode')
pc_data.head()
# Create Map
import folium

canada_map = folium.Map(location=[43.651070, -79.347015])

for lat, lng, borough, neighborhood in zip(pc_data['Latitude'], pc_data['Longitude'], pc_data['Borough'], pc_data['Neighbourhood']):
    label = '{}, {}'.format(neighborhood, borough)
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7,
        parse_html=False).add_to(canada_map)  
canada_map<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1613265879707701, 'fraction_numerical': 0.016301292861157952, 'mean_word_length': 4.426829268292683, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '497497', 'license': 'MIT', 'n_tokens_mistral': 669, 'n_tokens_neox': 648, 'n_words': 109, 'path': 'Data Gathering and Data Wrangling.ipynb', 'repo_name': 'Reactor11/Segmenting-and-Clustering-Neighborhoods-in-Toronto', 'size': '1779'}