<jupyter_start><jupyter_text>Finding the Best Neighborhood in Pittsburgh:  Factoring in Property ValuesData borrowed from https://data.wprdc.org/dataset/real-estate-sales  Getting Started<jupyter_code>import pandas as pd
import geopandas
import numpy as np
import plotly
# Importing the data
property_data = pd.read_csv("PghPropertySaleData.csv", low_memory = False)
# Previewing the data
property_data.head(5)
# In the preview, I noticed that the property in the fourth row sold for a price of $0.
# Looking through the .dbf file, I noticed that there are several other extremely low sold prices, such as $0, $1, and $10. 
# Therefore, I am only considering prices above $1,000 to mitigate the infuence of global outliers. 
property_data = property_data[property_data.PRICE > 1000]
# In importing the CSV file, the zip codes were turned into floats. This will cast them back into the int data type
property_data['PROPERTYZIP'] = property_data['PROPERTYZIP'].astype(int)
# Finding the mean of the property sold prices for all properties sharing the same zip code
price_property_data = property_data[['PROPERTYZIP','PRICE']].groupby(['PROPERTYZIP']).mean()
price_property_data
# Rounding the mean property sales prices to the nearest dollar
price_property_data['PRICE'] = price_property_data['PRICE'].astype(int)
# Sorting the data by price
price_property_data.sort_values(by=['PRICE'],inplace=True)
price_property_data.head(10)<jupyter_output><empty_output><jupyter_text>Establishing a points system and price bracketsZip codes with properties within a certain threshold will be assigned a fixed number of points.          Team members' data sets also utilize a point system.         The neighborood with the highest combined number of points will be considered the best.<jupyter_code># First, price brackets need to be established. To do this, I will divide the distribution into five tiers, based on percentiles.

# Creating a new column called "Percentile Rank", which shows the percentage of prices that any one price is greater than.
price_property_data['Percentile Rank'] = price_property_data.PRICE.rank(pct = True)
# Now, I am creating conditions for the program to check in order to set a point value based on the Percentile Rank values. 

conditions = [
    (price_property_data['Percentile Rank'] <= .2),
    (price_property_data['Percentile Rank'] > .2) & (price_property_data['Percentile Rank'] <= .4),
    (price_property_data['Percentile Rank'] > .4) & (price_property_data['Percentile Rank'] <= .6),
    (price_property_data['Percentile Rank'] > .6) & (price_property_data['Percentile Rank'] <= .8),
    (price_property_data['Percentile Rank'] > .8)]
# The points work with the above conditions. If the first condition is met (percentile rank below .2), one point is assigned.
# If the second condition is met (percentile rank below or equal to .4 and greater than .2), then two poitns are assigned.
# This method gives more points to zip codes with higher percentile prices.
points = ['1', '2', '3', '4', '5']
# Making a new column called "Points" and adding point values based on the above conditions.
price_property_data['Points'] = np.select(conditions, points)
# Sorting the data first by points, and then by price.
price_property_data.sort_values(by=['Points', 'PRICE'],inplace=True)
price_property_data.head(5)<jupyter_output><empty_output><jupyter_text>Visualizing the data<jupyter_code>price_property_data = price_property_data.astype(str)
price_property_data = price_property_data.reset_index()
conditions2 = [
    (price_property_data['PROPERTYZIP'] == '15028'),
    (price_property_data['PROPERTYZIP'] == '15089'),
    (price_property_data['PROPERTYZIP'] == '15104'),
    (price_property_data['PROPERTYZIP'] == '15110'),
    (price_property_data['PROPERTYZIP'] == '15045'),
    (price_property_data['PROPERTYZIP'] != '15089')]

points2 = ['Central Oakland', 'North Oakland', 'West Oakland', 'Crawford-Roberts', 'Strip District', 'Central Business District
           ']

price_property_data['neighborhood'] = np.select(conditions2, points2)

price_property_data.head(119)
neighborhoods = geopandas.read_file("Neighborhoods/Neighborhoods_.shp")
neighborhoods.plot()
property_values_map = neighborhoods.merge(price_property_data, how='left', left_on='hood',right_on='neighborhood')
property_values_map[['hood','PRICE','geometry']].head(50)
property_values_map.plot(column='PRICE')<jupyter_output><empty_output>