<jupyter_start><jupyter_text>Determining the best neighborhood in Pittsburgh  Our Metric We determined the best neighborhood in Pittsburgh by seeing which has the lowest rate of crime, estimated percent of population below the poverty line, and housing conditions. These three pieces of data can best be surmised as the total quality of life within a neighborhood.  Lowest rate of crimeThis section is focused on calculating the neighborhood that has the lowest crime per 100 persons.<jupyter_code>#Imports
import pandas as pd
import numpy as np
import math
%matplotlib inline
import matplotlib.pyplot as plt
#Intializing the pandas dataframe
crime = pd.read_csv("public-safety.csv", index_col="Neighborhood")
#dropping the unnecessary columns from the dataset
crime = crime.drop(crime.columns[[7,8,9,10,11,12,13]], axis=1)
#creating the new column by which I will be using as the main metric
crime["Total Crime per 100 persons"] = crime['Part 1 Crime per 100 Persons (2010)'] + crime['Part 2 Crime per 100 Persons (2010)']
crime.head(5)
#Sorting the values just to get an idea of what neighborhoods have high crime rates
crime.sort_values(by=['Part 1 Crime per 100 Persons (2010)'], ascending=False).head(5)
#Sorting to see what datasets have low crime
crime.sort_values(by=['Part 2 Crime per 100 Persons (2010)'], ascending=True).head(5)
#Again sorting to see what neighborhoods have low crime
crime.sort_values(by=['Part 1 Crime per 100 Persons (2010)'], ascending=True).head(5)
#Creating a new sorted data set to graph the lowest crime neighborhoods
crime_data = crime.sort_values(by=['Total Crime per 100 persons'], ascending=True)
crime_data['Total Crime per 100 persons'][:10].plot(kind="bar", ylabel='Crime per 100 Persons (2010)', title='Crime per 100 Persons vs. Neighborhood')
#Listing the top 10 data sets and their total crimes per 100 persons
crime_data['Total Crime per 100 persons'][:10]<jupyter_output><empty_output><jupyter_text>So from the end results we see Fairywood seems to be the lowest crime rate neighborhood. So our current scores are looking like1. Fairywood 10pts2. New Homestead 7pts3. Squirrel Hill North 3 pts4. Neighborhoods 4-10 1pt  Population under poverty line This section was focused on taking data about education and income and determining the neighborhood with the least amount of population below the poverty line.<jupyter_code>#Loading in Education - Income
inc = pd.read_csv("education-income.csv", index_col="Neighborhood")
inc.dropna()
#Just Checking the Raw data
inc.plot.bar()
#Dropping unnessisary columns
newpov = inc.drop(inc.columns[[0,1,2,3,4,5,6,7,8,9,10,11,12,13]], axis=1)
#Checking if everything is correct
newpov.head(5)
#Cleaning the Data, Some columns had 0% and 100% for poverty, which seems inaccurate
newpov = newpov.drop(['Chateau'])
newpov = newpov.drop(['North Shore'])
newpov = newpov.drop(['South Shore'])
newpov = newpov.drop(['West End'])
#Opening the data again
newpov.head(5)
#Converting the Est Percent Under Poverty (2010) to floats instead of strings
count = 0
#Instance Variable for a loop that goes through all values of newpov
while count < len(newpov):
    #Casting the strings inside newpov as a float by chopping off the % value from the end
    newpov['Est. Percent Under Poverty (2010)'][count] = float(newpov['Est. Percent Under Poverty (2010)'][count][:3])
    count = count + 1
#Openning the data up to check work
newpov.head(5)
#Now that the data is numerical, we can now order it
newpov = newpov.sort_values(by=["Est. Percent Under Poverty (2010)"], ascending=True)
newpov.head(5)

#Finally we are able to plot the data, only plotting the first ten to be readable.
newpov['Est. Percent Under Poverty (2010)'][:10].plot(kind="bar", ylabel="Est. Percent Under Poverty (2010) in Percent", title="Est. Percent Under Poverty plotted by Neighborhood for the ten lowest poverty rated neighborhoods in Pittsburgh")
#Dropping the head so it is easier to read
newpov.head(10)
#Just to get an overall picture of the city, here is the plot with all the values
newpov['Est. Percent Under Poverty (2010)'].plot(kind="bar", ylabel="Est. Percent Under Poverty (2010)",title="Est. Percent Under Poverty plotted by Neighborhood for every neighborhood in Pittsburgh")<jupyter_output><empty_output><jupyter_text>After analyzing the data and adding up the scores the scores from before and now:1. Fairywood & Regent Square 10 pts2. Swisshelm Park 8 pts3. Stript District 7 pts4. Lincoln Place & Stanton Heights 4 pts  Housing Conditions This final section is focused on the quality of houses compared to the population.<jupyter_code>import pandas as pd
file = pd.read_csv("built-enviornment-conditions.csv")
file
df = pd.read_csv("built-enviornment-conditions.csv")
df[u'% Good / Excellent Condition Buildings (2009)'] = df[u'% Good / Excellent Condition Buildings (2009)'].str.strip('%').astype(float)/100
df[u'% Average Condition Buildings (2009)'] = df[u'% Average Condition Buildings (2009)'].str.strip('%').astype(float)/100
df['%Average on Good&Average Condition Buildings'] = df[['% Good / Excellent Condition Buildings (2009)', '% Average Condition Buildings (2009)']].mean(axis=1)
df
newdata = df.sort_values("% Good / Excellent Condition Buildings (2009)", ascending=False).head(20)
df1 = newdata.loc[:,['Neighborhood','% Good / Excellent Condition Buildings (2009)','% Average Condition Buildings (2009)','%Average on Good&Average Condition Buildings']]
df1
condition = df1.sort_values("%Average on Good&Average Condition Buildings", ascending=False).head(15)
condition
df = pd.read_csv("built-enviornment-conditions.csv")
def con(column):
    column = column.replace(',', '')
    column = int(column)
    return column
df['Population (2010)'] = df['Population (2010)'].map(con)
df
SquareM = df['Land Area (acres)'].str.replace(',', '').astype(float)*0.0015625
df['Population Density'] = df['Population (2010)']/SquareM
df2 = df.sort_values("Population Density", ascending=True).head(45)
density = df2.loc[:,['Neighborhood','Population (2010)','Land Area (acres)','Population Density','Sector #']]
density
import matplotlib.pyplot as plt
plt.figure(figsize = (8,40))
plt.barh(density['Neighborhood'], density['Population Density'])
plt.title('Differences in Population Density')
plt.show()
df3 = pd.merge(condition,density,on='Neighborhood',how='inner')
df3
df3.loc[:,['Neighborhood','% Good / Excellent Condition Buildings (2009)','% Average Condition Buildings (2009)','%Average on Good&Average Condition Buildings','Population Density','Sector #']]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11448170731707318, 'fraction_numerical': 0.04100609756097561, 'mean_word_length': 6.077669902912621, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '627514', 'license': 'Unlicense', 'n_tokens_mistral': 2186, 'n_tokens_neox': 1912, 'n_words': 739, 'path': '.ipynb_checkpoints/Main-checkpoint.ipynb', 'repo_name': 'GAB8202/Best_Neighborhood', 'size': '6560'}