In [1]:
from __future__ import division, print_function, unicode_literals

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

In [4]:
foreclosure_accum_df = pd.read_csv('ihs_data/IHS_Foreclosure_Accumulation_chicago-community-areas.csv')
foreclosure_accum_df['Percentage_Foreclosed_Parcels'] = foreclosure_accum_df['Percentage_Foreclosed_Parcels'].str[:-1].astype(float)
foreclosure_accum_df.head()


Out[4]:
Community_Area Percentage_Foreclosed_Parcels
0 City of Chicago Total 19.6
1 Albany Park 20.1
2 Archer Heights 20.7
3 Armour Square 3.5
4 Ashburn 27.2

In [10]:
foreclosure_filings_df = pd.read_csv('ihs_data/IHS_Foreclosure_Filings_chicago-community-areas.csv')
foreclosure_filings_df = foreclosure_filings_df.fillna(0)
foreclosure_filings_df['Foreclosure_Filings_05_15'] = foreclosure_filings_df[['All_Res_2005', 'All_Res_2006', 'All_Res_2007',
                                                                              'All_Res_2008', 'All_Res_2009', 'All_Res_2010',
                                                                              'All_Res_2011', 'All_Res_2012', 'All_Res_2013',
                                                                              'All_Res_2014', 'All_Res_2015']].sum(axis=1)
foreclosure_filings_df = foreclosure_filings_df[['Community_Area', 'Foreclosure_Filings_05_15']]
foreclosure_filings_df.head()


Out[10]:
Community_Area Foreclosure_Filings_05_15
0 Albany Park 1679
1 Archer Heights 623
2 Armour Square 106
3 Ashburn 4028
4 Auburn Gresham 4115

In [14]:
foreclosure_parcels_df = pd.read_csv('ihs_data/IHS_Foreclosures_per_Parcel_chicago-community-areas.csv')
foreclosure_parcels_df['Foreclosures_per_Parcel_Mean_05_15'] = foreclosure_parcels_df[foreclosure_parcels_df.columns.values[1:]].mean(axis=1)
foreclosure_parcels_df = foreclosure_parcels_df[['Community_Area', 'Foreclosures_per_Parcel_Mean_05_15']]
foreclosure_parcels_df.head()


Out[14]:
Community_Area Foreclosures_per_Parcel_Mean_05_15
0 Albany Park 2.045455
1 Archer Heights 2.318182
2 Armour Square 0.345455
3 Ashburn 3.300000
4 Auburn Gresham 3.727273

In [25]:
low_value_df = pd.read_csv('ihs_data/IHS_Share_Low_Value_chicago-community-areas.csv')
low_value_df = low_value_df.fillna(0)
res_columns_05_15 = ['All_Res_2005', 'All_Res_2006', 'All_Res_2007',
                     'All_Res_2008', 'All_Res_2009', 'All_Res_2010',
                     'All_Res_2011', 'All_Res_2012', 'All_Res_2013',
                     'All_Res_2014', 'All_Res_2015']
low_value_df[res_columns_05_15] = low_value_df[res_columns_05_15].applymap(lambda x: x[:-1]).astype(float)
low_value_df['Share_Low_Value_Mean_05_15'] = low_value_df[res_columns_05_15].mean(axis=1)
low_value_df = low_value_df[['Community_Area', 'Share_Low_Value_Mean_05_15']]
low_value_df.head()


Out[25]:
Community_Area Share_Low_Value_Mean_05_15
0 Albany Park 0.463636
1 Archer Heights 0.400000
2 Armour Square 0.700000
3 Ashburn 0.527273
4 Auburn Gresham 8.109091

In [30]:
vacant_df = pd.read_csv('ihs_data/IHS_Share_Vacant_chicago-community-areas.csv')
vacant_df[vacant_df.columns.values[1:]] = vacant_df[vacant_df.columns.values[1:]].applymap(lambda x: x[:-1]).astype(float)
vacant_df['Vacant_Percent_Mean_10_15'] = vacant_df[vacant_df.columns.values[1:]].mean(axis=1)
vacant_df = vacant_df[['Community_Area', 'Vacant_Percent_Mean_10_15']]
vacant_df.head()


Out[30]:
Community_Area Vacant_Percent_Mean_10_15
0 Albany Park 1.810
1 Archer Heights 1.245
2 Armour Square 0.780
3 Ashburn 0.990
4 Auburn Gresham 3.235

In [32]:
combined_ihs_df = pd.merge(foreclosure_accum_df, foreclosure_filings_df, on='Community_Area'
                          ).merge(foreclosure_parcels_df, on='Community_Area').merge(low_value_df, on='Community_Area'
                          ).merge(vacant_df, on='Community_Area')
combined_ihs_df.head()


Out[32]:
Community_Area Percentage_Foreclosed_Parcels Foreclosure_Filings_05_15 Foreclosures_per_Parcel_Mean_05_15 Share_Low_Value_Mean_05_15 Vacant_Percent_Mean_10_15
0 Albany Park 20.1 1679 2.045455 0.463636 1.810
1 Archer Heights 20.7 623 2.318182 0.400000 1.245
2 Armour Square 3.5 106 0.345455 0.700000 0.780
3 Ashburn 27.2 4028 3.300000 0.527273 0.990
4 Auburn Gresham 30.7 4115 3.727273 8.109091 3.235

In [33]:
combined_ihs_df = combined_ihs_df.rename(columns={'Community_Area':'Community Area'})
combined_ihs_df.head()


Out[33]:
Community Area Percentage_Foreclosed_Parcels Foreclosure_Filings_05_15 Foreclosures_per_Parcel_Mean_05_15 Share_Low_Value_Mean_05_15 Vacant_Percent_Mean_10_15
0 Albany Park 20.1 1679 2.045455 0.463636 1.810
1 Archer Heights 20.7 623 2.318182 0.400000 1.245
2 Armour Square 3.5 106 0.345455 0.700000 0.780
3 Ashburn 27.2 4028 3.300000 0.527273 0.990
4 Auburn Gresham 30.7 4115 3.727273 8.109091 3.235

In [34]:
combined_ihs_df.to_csv('ihs_data/combined_ihs_data.csv',index=False)

In [ ]: