<jupyter_start><jupyter_text>**Segmenting and Clustering Neighbourhoods in Toronto** ---<jupyter_code>import requests
import lxml.html as lh
import bs4 as bs
import urllib.request
import numpy as np 
import pandas as pd
url = "https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M"
res = requests.get(url)
soup = bs.BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[0]
df = pd.read_html(str(table))
data = pd.read_json(df[0].to_json(orient='records'))
data.head()
raw_data_selected = data[data['Borough'] != 'Not assigned']
raw_data_selected = raw_data_selected.groupby(['Borough', 'Postal Code'], as_index=False).agg(','.join)
raw_data_selected.head()
raw_data_selected['Neighborhood'] = np.where(raw_data_selected['Neighborhood'] == 'Not assigned', raw_data_selected['Borough'], raw_data_selected['Neighborhood'])
raw_data_selected.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1476510067114094, 'fraction_numerical': 0.003355704697986577, 'mean_word_length': 8.623655913978494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '360958', 'license': 'MIT', 'n_tokens_mistral': 324, 'n_tokens_neox': 313, 'n_words': 56, 'path': 'Segmenting and Clustering Neighbourhoods inToronto/Part1.ipynb', 'repo_name': 'ayoubn/applied-data-science-capstone', 'size': '894'}