<jupyter_start><jupyter_text>Capstone Project Notebook - Week 3 - Part 2*Author: <NAME>*This notebook will be mainly used for the capstone project<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Use the Notebook to build the code to scrape the following Wikipedia page, https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_MThe dataframe will consist of three columns: PostalCode, Borough, and Neighborhood<jupyter_code>postal_codes = pd.read_html('https://en.wikipedia.org/wiki/List_of_postal_codes_of_Canada:_M', attrs={'class': 'wikitable'}, header='infer')[0]
postal_codes.columns = ['PostalCode', 'Borough', 'Neighborhood']<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>postal_codes = postal_codes[postal_codes.Borough != 'Not assigned'].reset_index(drop=True)<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 as shown in row 11 in the above table.<jupyter_code>postal_codes.Neighborhood += ', '
postal_codes = postal_codes.groupby(['PostalCode', 'Borough']).Neighborhood.sum().str.strip(', ').reset_index()<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. So for the 9th cell in the table on the Wikipedia page, the value of the Borough and the Neighborhood columns will be Queen's Park.<jupyter_code>postal_codes.Neighborhood = [n if n != 'Not Assigned' else b for b, n in postal_codes[['Borough', 'Neighborhood']].values]<jupyter_output><empty_output><jupyter_text>**Result:**<jupyter_code>postal_codes<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>postal_codes.shape<jupyter_output><empty_output><jupyter_text>Now that you have built a dataframe of the postal code of each neighborhood along with the borough name and neighborhood name, in order to utilize the Foursquare location data, we need to get the latitude and the longitude coordinates of each neighborhood....Given that this package can be very unreliable, in case you are not able to get the geographical coordinates of the neighborhoods using the Geocoder package, here is a link to a csv file that has the geographical coordinates of each postal code: http://cocl.us/Geospatial_data<jupyter_code>geospatial_coordinates = pd.read_csv('Geospatial_Coordinates.csv')
postal_codes_geospatial = postal_codes.merge(geospatial_coordinates, left_on='PostalCode', right_on='Postal Code').drop('Postal Code', axis=1)
postal_codes_geospatial<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup