<jupyter_start><jupyter_text>Segmenting and Clustering Neighborhoods in Toronto<jupyter_code>import pandas as pd
import numpy as np
import re<jupyter_output><empty_output><jupyter_text>obtain the data that is in the table of postal codes and transform the data into a pandas dataframe<jupyter_code>wikidata = pd.read_html("https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M", 
             match='Postcode', header=0)[0]<jupyter_output><empty_output><jupyter_text>The dataframe will consist of three columns: PostalCode, Borough, and Neighborhood<jupyter_code>wikidata = wikidata.rename(
    mapper={'Postcode':'PostalCode', 'Neighbourhood':'Neighborhood'},
    axis=1)
wikidata.head()<jupyter_output><empty_output><jupyter_text>Only process the cells that have an assigned borough. Ignore cells with a borough that is Not assigned.<jupyter_code>befrows = wikidata.shape[0]
wikidata = wikidata[wikidata['Borough']!='Not assigned']
assert wikidata.shape[0] < befrows, "No rows were removed"<jupyter_output><empty_output><jupyter_text>More than one neighborhood can exist in one postal code area. For example, in the table on the Wikipedia page, you will notice that M5A is listed twice and has two neighborhoods: Harbourfront and Regent Park. These two rows will be combined into one row with the neighborhoods separated with a comma<jupyter_code>grouped = wikidata.groupby(['PostalCode','Borough'], 
                           as_index=False).aggregate(lambda x: ', '.join(x))<jupyter_output><empty_output><jupyter_text>If a cell has a borough but a Not assigned neighborhood, then the neighborhood will be the same as the borough.<jupyter_code>for index, row in grouped.iterrows():
    row['Neighborhood'] = row['Borough'] if re.search('Not assigned', row['Neighborhood']) else row['Neighborhood']<jupyter_output><empty_output><jupyter_text>In the last cell of your notebook, use the .shape method to print the number of rows of your dataframe.<jupyter_code>grouped.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09528535980148883, 'fraction_numerical': 0.002977667493796526, 'mean_word_length': 6.439114391143911, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '52021', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 645, 'n_tokens_neox': 619, 'n_words': 185, 'path': 'Segmenting and Clustering Neighborhoods in Toronto, Canada.ipynb', 'repo_name': 'davidschneider04/Coursera_Capstone', 'size': '2015'}