{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# DCIC Mapping Inequality : Baltimore " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Importing the Data and Creating a Data Frame" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FormStateCitySecurity_GradeArea_NumberTerrain_DescriptionFavorable_InfluencesDetrimental_InfluencesINHABITANTS_TypeINHABITANTS_Annual_Income...INHABITANTS_Population_IncreaseINHABITANTS_Population_DecreaseINHABITANTS_Population_StaticBUILDINGS_TypesBUILDINGS_ConstructionBUILDINGS_AgeBUILDINGS_RepairTen_Fifteen_DesirabilityRemarksDate
0NS FORM-8 6-1-37MarylandBaltimoreA2RollingFairly new suburban area of homogeneous charac...NoneSubstantial Middle Class$3000 - 5,000...FastNaNNaNDetached an row housesBrick and frame1 to 10 yearsGoodUpwardA recent development with much room for expans...May 4,1937
1NS FORM-8 6-1-37MarylandBaltimoreA1UndulatingVery nicely planned residential area of medium...NoneExecutives, Professional Menover $5000...Moderately FastNaNNaNSingle family detachedBrick and Stone12 yearsVery goodUpwardMostly fee properties. A few homes valued at $...May 4,1937
2NS FORM-8 6-1-37MarylandBaltimoreA3RollingGood residential area. Well planned.Distance to CityExecutives, Professional Men3500 - 7000...Moderately FastNaNNaNOne family detachedBrick, Stone, and Frame1 to 20 yearsGood to excellentUpwardPrincipally fee property. This section lies in...May 4,1937
3NS FORM-8 6-1-37MarylandBaltimoreA4LevelWell planned development of fairlyNoneProfessional and Executivesover $5000...SlowlyNaNNaNOne familyBrick, Stone, and Frame10 yearsGoodUpwardAll fee propertyMay 4,1937
4NS FORM-8 6-1-37MarylandBaltimoreA5UndulatingDesirable residential section. Good quality, m...NoneExecutives, Professional Men$3,500 - $10,000...Moderately FastNaNNaNOne family detachedBrick and Stone1 to 20 yearsGoodUpwardMerridale only recently developed. Prices do n...NaN
\n", "

5 rows × 26 columns

\n", "
" ], "text/plain": [ " Form State City Security_Grade Area_Number \\\n", "0 NS FORM-8 6-1-37 Maryland Baltimore A 2 \n", "1 NS FORM-8 6-1-37 Maryland Baltimore A 1 \n", "2 NS FORM-8 6-1-37 Maryland Baltimore A 3 \n", "3 NS FORM-8 6-1-37 Maryland Baltimore A 4 \n", "4 NS FORM-8 6-1-37 Maryland Baltimore A 5 \n", "\n", " Terrain_Description Favorable_Influences \\\n", "0 Rolling Fairly new suburban area of homogeneous charac... \n", "1 Undulating Very nicely planned residential area of medium... \n", "2 Rolling Good residential area. Well planned. \n", "3 Level Well planned development of fairly \n", "4 Undulating Desirable residential section. Good quality, m... \n", "\n", " Detrimental_Influences INHABITANTS_Type \\\n", "0 None Substantial Middle Class \n", "1 None Executives, Professional Men \n", "2 Distance to City Executives, Professional Men \n", "3 None Professional and Executives \n", "4 None Executives, Professional Men \n", "\n", " INHABITANTS_Annual_Income ... INHABITANTS_Population_Increase \\\n", "0 $3000 - 5,000 ... Fast \n", "1 over $5000 ... Moderately Fast \n", "2 3500 - 7000 ... Moderately Fast \n", "3 over $5000 ... Slowly \n", "4 $3,500 - $10,000 ... Moderately Fast \n", "\n", " INHABITANTS_Population_Decrease INHABITANTS_Population_Static \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN \n", "\n", " BUILDINGS_Types BUILDINGS_Construction BUILDINGS_Age \\\n", "0 Detached an row houses Brick and frame 1 to 10 years \n", "1 Single family detached Brick and Stone 12 years \n", "2 One family detached Brick, Stone, and Frame 1 to 20 years \n", "3 One family Brick, Stone, and Frame 10 years \n", "4 One family detached Brick and Stone 1 to 20 years \n", "\n", " BUILDINGS_Repair Ten_Fifteen_Desirability \\\n", "0 Good Upward \n", "1 Very good Upward \n", "2 Good to excellent Upward \n", "3 Good Upward \n", "4 Good Upward \n", "\n", " Remarks Date \n", "0 A recent development with much room for expans... May 4,1937 \n", "1 Mostly fee properties. A few homes valued at $... May 4,1937 \n", "2 Principally fee property. This section lies in... May 4,1937 \n", "3 All fee property May 4,1937 \n", "4 Merridale only recently developed. Prices do n... NaN \n", "\n", "[5 rows x 26 columns]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Loads the Pandas library \n", "import pandas as pd\n", "\n", "# Creates data frame (df) by reading in the Baltimore csv\n", "df = pd.read_csv(\"AD_Data_BaltimoreProject.csv\")\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": [ "Form object\n", "State object\n", "City object\n", "Security_Grade object\n", "Area_Number int64\n", "Terrain_Description object\n", "Favorable_Influences object\n", "Detrimental_Influences object\n", "INHABITANTS_Type object\n", "INHABITANTS_Annual_Income object\n", "INHABITANTS_Foreignborn object\n", "INHABITANTS_F float64\n", "INHABITANTS_Negro object\n", "INHABITANTS_N object\n", "INHABITANTS_Infiltration object\n", "INHABITANTS_Relief_Families object\n", "INHABITANTS_Population_Increase object\n", "INHABITANTS_Population_Decrease object\n", "INHABITANTS_Population_Static object\n", "BUILDINGS_Types object\n", "BUILDINGS_Construction object\n", "BUILDINGS_Age object\n", "BUILDINGS_Repair object\n", "Ten_Fifteen_Desirability object\n", "Remarks object\n", "Date object\n", "dtype: object" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Lists all the columns of the data frame\n", "df.dtypes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data Cleaning " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Foreignborn Inhabitants " ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "0 No\n", "1 None\n", "2 None\n", "3 None\n", "4 None\n", "5 NaN\n", "6 No\n", "7 No\n", "8 No\n", "9 Small\n", "10 Very few\n", "11 No\n", "12 No\n", "13 No\n", "14 No\n", "15 Mixture\n", "16 None\n", "17 Few\n", "18 No\n", "19 No\n", "20 None\n", "21 None\n", "22 No\n", "23 No\n", "24 No\n", "25 NaN\n", "26 NaN\n", "27 NaN\n", "28 No\n", "29 Small\n", "30 None\n", "31 No\n", "32 Mixture \n", "33 Mixture\n", "34 Mixture\n", "35 No\n", "36 Mixture\n", "37 Mixture\n", "38 Mixture\n", "39 Mixture\n", "40 Mixture\n", "41 Nominal\n", "42 NaN\n", "43 NaN\n", "44 Nominal\n", "45 NaN\n", "46 NaN\n", "47 NaN\n", "48 NaN\n", "49 NaN\n", "50 Italians\n", "51 Polish\n", "52 Mixture\n", "53 Mixture\n", "54 Mixture\n", "55 Mixture\n", "56 Mixture\n", "Name: INHABITANTS_Foreignborn, dtype: object" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.INHABITANTS_Foreignborn" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": [ "0 None\n", "1 None\n", "2 None\n", "3 None\n", "4 None\n", "5 Yes\n", "6 None\n", "7 None\n", "8 None\n", "9 Yes\n", "10 Yes\n", "11 None\n", "12 None\n", "13 None\n", "14 None\n", "15 Yes\n", "16 None\n", "17 Yes\n", "18 None\n", "19 None\n", "20 None\n", "21 None\n", "22 None\n", "23 None\n", "24 None\n", "25 Yes\n", "26 Yes\n", "27 Yes\n", "28 None\n", "29 Yes\n", "30 None\n", "31 None\n", "32 Yes\n", "33 Yes\n", "34 Yes\n", "35 None\n", "36 Yes\n", "37 Yes\n", "38 Yes\n", "39 Yes\n", "40 Yes\n", "41 Yes\n", "42 Yes\n", "43 Yes\n", "44 Yes\n", "45 Yes\n", "46 Yes\n", "47 Yes\n", "48 Yes\n", "49 Yes\n", "50 Yes\n", "51 Yes\n", "52 Yes\n", "53 Yes\n", "54 Yes\n", "55 Yes\n", "56 Yes\n", "Name: INHABITANTS_Foreignborn, dtype: object" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Replaces the values of 'No' with 'None'\n", "df['INHABITANTS_Foreignborn'] = df['INHABITANTS_Foreignborn'].replace('No', 'None')\n", "\n", "# Replaces all other values with 'Yes'\n", "for value in df['INHABITANTS_Foreignborn']:\n", " if value != 'None':\n", " df['INHABITANTS_Foreignborn'] = df['INHABITANTS_Foreignborn'].replace(value, 'Yes')\n", "df.INHABITANTS_Foreignborn" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }