{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Which college district has the fewest low-income families?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> * 🔬 Data Science\n", "* 🥠 Statistics\n", "* 👟 Ready To Run!" ] }, { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Table of Contents

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Doing well by doing good\n", "A local cable provider has been running a pilot program in the county to provide low-cost computers and internet access to low-income families with kids in high school. There has been a marked improvement in school performance for these kids, and the program has brought the company a fair amount of positive publicity and goodwill in the community.\n", "\n", "Company officials are now considering setting up a similar program for community college students. The company provides internet access to the five community college districts in the county, and officials are aware that the colleges are under a lot of pressure—they are facing funding cuts at the same time as increased demand for enrollment. To try to improve the situation the colleges are turning more and more to distance learning, primarily via the internet. By providing computers and internet access, the cable company can enable more low-income students to take advantage of online classes.\n", "\n", "### Starting small\n", "The company wants to start with a small pilot program in one district. To be fair they will have to offer the low-cost computers and internet access to any low-income students in the district—if they pick a district with many such students the program may be overwhelmed from the start. So they will set up the pilot program in the district that has the fewest low-income households.\n", "The program is run out of the company's marketing division, so an analyst in that division is tasked with finding out which district has the fewest low-income families. To do the analysis, he'll use ArcGIS to sum the number of low-income families in census tracts that fall within each district.\n", "\n", "Note:\n", "This example presents an approach to using ArcGIS to find out how many low-income families are within each community college district. While the data is real, the scenario, analysis, and resulting decisions are hypothetical. The purpose of the example is to illustrate the type of problem that can be addressed by summarizing information by area features." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Connect to your GIS\n", "\n", "Establish a connection to your organization which could be an ArcGIS Online organization or an ArcGIS Enterprise. To be able to run the code using ArcGIS API for Python, you would need to provide credentials of a user within an ArcGIS Online organization." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from arcgis.gis import GIS\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "gis = GIS(\"home\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Search the data and begin performing the analysis\n", "\n", "Accessing the content property of your gis object you can use the search() method. Search for **CensusTractIncome**." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "income_data = gis.content.search('title:CensusTractIncome', 'Feature layer')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Search for **Community_College_dist**" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "dist_data = gis.content.search('title:Community_College_District', 'Feature layer')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Import the display module to display the items" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " CensusTractIncome\n", " \n", "
Feature Layer Collection by yjiang\n", "
Last Modified: January 04, 2019\n", "
0 comments, 2 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import display\n", "\n", "for item in income_data:\n", " display(item)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " community_college_district_2\n", " \n", "
Feature Layer Collection by yjiang\n", "
Last Modified: January 04, 2019\n", "
0 comments, 3 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import display\n", "\n", "for item in dist_data:\n", " display(item)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "inc_item = income_data[0]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "dist_item = dist_data[0]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CensusTractIncome\n" ] } ], "source": [ "for lyr in inc_item.layers:\n", " print(lyr.properties.name)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "community_college_district_2\n" ] } ], "source": [ "for lyr in dist_item.layers:\n", " print(lyr.properties.name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since the item is a Feature Layer Collection, accessing the layers property will give us a list of FeatureLayer objects." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "inc_lyr = inc_item.layers[0]\n", "dis_lyr = dist_item.layers[0] " ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m1 = gis.map('San Diego')\n", "m1" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "m1.add_layer(dis_lyr)\n", "m1.add_layer(inc_lyr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find the community college district with the fewest low income families" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "From the regional association of governments GIS database, the analyst loads a layer of the community college district boundaries and a layer of census tracts. The census tract data includes the number of households in each of several income categories, such as less than $10,000, $10,000 to $15,000, $15,000 to $20,000, and so on.\n", "\n", "The standard the company has been using for the high school program is to provide support to families with an annual income less than $30,000.\n", "\n", "They will use this same standard for the community college program.The analyst adds a field to the census tract layer and sums the number of households in each tract with income less than $30,000." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Convert the layer into pandas dataframe to calculate the number of households in each tract with less than $30,000." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "sdf = pd.DataFrame.spatial.from_layer(inc_lyr)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "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", "
SHAPEfidincome_100income_10kincome_125income_150income_15kincome_200income_20kincome_25kincome_30kincome_35kincome_40kincome_45kincome_50kincome_60kincome_75kincome_allincome_lestract
0{\"rings\": [[[-13051046.674600001, 3866695.3332...13792057312715812519522927927821230444552637041482437700
1{\"rings\": [[[-13049196.649199996, 3869830.7043...21071326452180916013525011617511528026317825102947800
2{\"rings\": [[[-13051806.579200003, 3868598.5098...315015649421542519120923316819718832539323329532407901
3{\"rings\": [[[-13050375.521200001, 3868973.9773...412416330431841917417113919514714328814531024291547903
4{\"rings\": [[[-13050786.626600001, 3868042.6255...516221953671871920821819918818417230431632631573357904
\n", "
" ], "text/plain": [ " SHAPE fid income_100 \\\n", "0 {\"rings\": [[[-13051046.674600001, 3866695.3332... 1 379 \n", "1 {\"rings\": [[[-13049196.649199996, 3869830.7043... 2 107 \n", "2 {\"rings\": [[[-13051806.579200003, 3868598.5098... 3 150 \n", "3 {\"rings\": [[[-13050375.521200001, 3868973.9773... 4 124 \n", "4 {\"rings\": [[[-13050786.626600001, 3868042.6255... 5 162 \n", "\n", " income_10k income_125 income_150 income_15k income_200 income_20k \\\n", "0 205 73 127 158 125 195 \n", "1 132 64 52 180 9 160 \n", "2 156 49 42 154 25 191 \n", "3 163 30 43 184 19 174 \n", "4 219 53 67 187 19 208 \n", "\n", " income_25k income_30k income_35k income_40k income_45k income_50k \\\n", "0 229 279 278 212 304 445 \n", "1 135 250 116 175 115 280 \n", "2 209 233 168 197 188 325 \n", "3 171 139 195 147 143 288 \n", "4 218 199 188 184 172 304 \n", "\n", " income_60k income_75k income_all income_les tract \n", "0 526 370 4148 243 7700 \n", "1 263 178 2510 294 7800 \n", "2 393 233 2953 240 7901 \n", "3 145 310 2429 154 7903 \n", "4 316 326 3157 335 7904 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sdf.head()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "sdf['income_lt_30k'] = sdf['income_les']+sdf['income_10k']+sdf['income_15k']+sdf['income_20k']+sdf['income_25k']" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 1030\n", "1 901\n", "2 950\n", "3 846\n", "4 1167\n", "Name: income_lt_30k, dtype: int64" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sdf.income_lt_30k.head()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "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", " \n", "
SHAPEfidincome_100income_10kincome_125income_150income_15kincome_200income_20kincome_25k...income_35kincome_40kincome_45kincome_50kincome_60kincome_75kincome_allincome_lestractincome_lt_30k
0{\"rings\": [[[-13051046.674600001, 3866695.3332...137920573127158125195229...278212304445526370414824377001030
1{\"rings\": [[[-13049196.649199996, 3869830.7043...210713264521809160135...11617511528026317825102947800901
2{\"rings\": [[[-13051806.579200003, 3868598.5098...3150156494215425191209...16819718832539323329532407901950
3{\"rings\": [[[-13050375.521200001, 3868973.9773...4124163304318419174171...19514714328814531024291547903846
4{\"rings\": [[[-13050786.626600001, 3868042.6255...5162219536718719208218...188184172304316326315733579041167
\n", "

5 rows × 21 columns

\n", "
" ], "text/plain": [ " SHAPE fid income_100 \\\n", "0 {\"rings\": [[[-13051046.674600001, 3866695.3332... 1 379 \n", "1 {\"rings\": [[[-13049196.649199996, 3869830.7043... 2 107 \n", "2 {\"rings\": [[[-13051806.579200003, 3868598.5098... 3 150 \n", "3 {\"rings\": [[[-13050375.521200001, 3868973.9773... 4 124 \n", "4 {\"rings\": [[[-13050786.626600001, 3868042.6255... 5 162 \n", "\n", " income_10k income_125 income_150 income_15k income_200 income_20k \\\n", "0 205 73 127 158 125 195 \n", "1 132 64 52 180 9 160 \n", "2 156 49 42 154 25 191 \n", "3 163 30 43 184 19 174 \n", "4 219 53 67 187 19 208 \n", "\n", " income_25k ... income_35k income_40k income_45k income_50k \\\n", "0 229 ... 278 212 304 445 \n", "1 135 ... 116 175 115 280 \n", "2 209 ... 168 197 188 325 \n", "3 171 ... 195 147 143 288 \n", "4 218 ... 188 184 172 304 \n", "\n", " income_60k income_75k income_all income_les tract income_lt_30k \n", "0 526 370 4148 243 7700 1030 \n", "1 263 178 2510 294 7800 901 \n", "2 393 233 2953 240 7901 950 \n", "3 145 310 2429 154 7903 846 \n", "4 316 326 3157 335 7904 1167 \n", "\n", "[5 rows x 21 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sdf.head()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(605, 21)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sdf.shape" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "cols = sdf.columns.tolist()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "cols = cols[-1:] + cols[:-1]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "df = sdf[cols]" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "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", " \n", "
income_lt_30kSHAPEfidincome_100income_10kincome_125income_150income_15kincome_200income_20k...income_30kincome_35kincome_40kincome_45kincome_50kincome_60kincome_75kincome_allincome_lestract
01030{\"rings\": [[[-13051046.674600001, 3866695.3332...137920573127158125195...27927821230444552637041482437700
1901{\"rings\": [[[-13049196.649199996, 3869830.7043...210713264521809160...25011617511528026317825102947800
2950{\"rings\": [[[-13051806.579200003, 3868598.5098...3150156494215425191...23316819718832539323329532407901
3846{\"rings\": [[[-13050375.521200001, 3868973.9773...4124163304318419174...13919514714328814531024291547903
41167{\"rings\": [[[-13050786.626600001, 3868042.6255...5162219536718719208...19918818417230431632631573357904
\n", "

5 rows × 21 columns

\n", "
" ], "text/plain": [ " income_lt_30k SHAPE fid \\\n", "0 1030 {\"rings\": [[[-13051046.674600001, 3866695.3332... 1 \n", "1 901 {\"rings\": [[[-13049196.649199996, 3869830.7043... 2 \n", "2 950 {\"rings\": [[[-13051806.579200003, 3868598.5098... 3 \n", "3 846 {\"rings\": [[[-13050375.521200001, 3868973.9773... 4 \n", "4 1167 {\"rings\": [[[-13050786.626600001, 3868042.6255... 5 \n", "\n", " income_100 income_10k income_125 income_150 income_15k income_200 \\\n", "0 379 205 73 127 158 125 \n", "1 107 132 64 52 180 9 \n", "2 150 156 49 42 154 25 \n", "3 124 163 30 43 184 19 \n", "4 162 219 53 67 187 19 \n", "\n", " income_20k ... income_30k income_35k income_40k income_45k \\\n", "0 195 ... 279 278 212 304 \n", "1 160 ... 250 116 175 115 \n", "2 191 ... 233 168 197 188 \n", "3 174 ... 139 195 147 143 \n", "4 208 ... 199 188 184 172 \n", "\n", " income_50k income_60k income_75k income_all income_les tract \n", "0 445 526 370 4148 243 7700 \n", "1 280 263 178 2510 294 7800 \n", "2 325 393 233 2953 240 7901 \n", "3 288 145 310 2429 154 7903 \n", "4 304 316 326 3157 335 7904 \n", "\n", "[5 rows x 21 columns]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Importing the spatial dataframe back into a layer, Accessing the content property of your gis object you can use the `import_data()` method." ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "census_tract = gis.content.import_data(df, title='census_tract2', tags='censustrack')" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " census_tract2\n", " \n", "
Feature Layer Collection by yjiang\n", "
Last Modified: January 04, 2019\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "census_tract" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get the number of low-income households in each district" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The analyst then summarizes census tracts by community college districts to sum the number of low-income households in each district. If a tract falls in two or more districts, the value for that tract will be split proportionally between the districts (based on the area of the tract in each district)." ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "from arcgis.features.summarize_data import summarize_within" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "summary = summarize_within(dis_lyr, census_tract, summary_fields=[\"income_lt_ SUM\"],\n", " shape_units='SquareMiles', output_name='district_summary')" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " district_summary\n", " \n", "
Feature Layer Collection by yjiang\n", "
Last Modified: January 04, 2019\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "summary" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m2 = gis.map('San Diego')\n", "m2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The map displays the census tracts color-coded by the number of households in each census tract with income less than $30,000 per year." ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "m2.add_layer(summary)" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "summ_lyr = summary.layers[0]" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['SHAPE',\n", " 'analysisarea',\n", " 'district',\n", " 'objectid',\n", " 'objectid_1',\n", " 'shape__are',\n", " 'shape__len',\n", " 'shape_leng',\n", " 'sum_area_squaremiles',\n", " 'sum_income_lt_']" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sdf2 = pd.DataFrame.spatial.from_layer(summ_lyr)\n", "cols2 = sdf2.columns.tolist()\n", "cols2" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "sdf2.sort_values(['sum_income_lt_'], inplace=True)" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "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", "
SHAPEanalysisareadistrictobjectidobjectid_1shape__areshape__lenshape_lengsum_area_squaremilessum_income_lt_
2{\"rings\": [[[-13069560.232299998, 3941041.6564...180.057307MIRA COSTA COMMUNITY COLLEGE336.666802e+08193041.7051585.292542e+05179.90496728288.0
4{\"rings\": [[[-13045570.419099998, 3857253.9374...171.343530SOUTHWESTERN COMMUNITY COLLEGE556.272847e+08175596.8546114.845452e+05171.08580140861.0
0{\"rings\": [[[-13000869.2404, 3890488.430200003...1137.329793GROSSMONT-CUYAMACA COMMUNITY COLLEGE114.176966e+09349055.6944659.623860e+051137.09373348777.0
1{\"rings\": [[[-13078663.771200003, 3962536.5573...2554.787820PALOMAR COMMUNITY COLLEGE229.475183e+09560765.0102951.538205e+062554.69555456549.0
3{\"rings\": [[[-13039483.616799999, 3888486.6244...217.585900SAN DIEGO COMMUNITY COLLEGE447.999274e+08221005.4747876.086365e+05217.566586127843.0
\n", "
" ], "text/plain": [ " SHAPE analysisarea \\\n", "2 {\"rings\": [[[-13069560.232299998, 3941041.6564... 180.057307 \n", "4 {\"rings\": [[[-13045570.419099998, 3857253.9374... 171.343530 \n", "0 {\"rings\": [[[-13000869.2404, 3890488.430200003... 1137.329793 \n", "1 {\"rings\": [[[-13078663.771200003, 3962536.5573... 2554.787820 \n", "3 {\"rings\": [[[-13039483.616799999, 3888486.6244... 217.585900 \n", "\n", " district objectid objectid_1 shape__are \\\n", "2 MIRA COSTA COMMUNITY COLLEGE 3 3 6.666802e+08 \n", "4 SOUTHWESTERN COMMUNITY COLLEGE 5 5 6.272847e+08 \n", "0 GROSSMONT-CUYAMACA COMMUNITY COLLEGE 1 1 4.176966e+09 \n", "1 PALOMAR COMMUNITY COLLEGE 2 2 9.475183e+09 \n", "3 SAN DIEGO COMMUNITY COLLEGE 4 4 7.999274e+08 \n", "\n", " shape__len shape_leng sum_area_squaremiles sum_income_lt_ \n", "2 193041.705158 5.292542e+05 179.904967 28288.0 \n", "4 175596.854611 4.845452e+05 171.085801 40861.0 \n", "0 349055.694465 9.623860e+05 1137.093733 48777.0 \n", "1 560765.010295 1.538205e+06 2554.695554 56549.0 \n", "3 221005.474787 6.086365e+05 217.566586 127843.0 " ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sdf2.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This shows that one of the community college districts has by far the fewest households with income less than $30,000—this district will be used for the cable provider's pilot program. The values were calculated by summing the values for the tracts within each community college district." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualization to show district with fewest households" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m3 = gis.map('San Diego')\n", "m3" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [], "source": [ "m3.add_layer(summary, {\"renderer\":\"ClassedSizeRenderer\", \"field_name\": \"SUM_income_lt_\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It's clear that the Mira Costa district has by far the fewest low-income households. That's where the pilot program will be set up." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusion\n", "In this notebook, we have discussed how to examine, summarize, and visualize which college district has the fewest low income families with spatially enabled dataframe and spatial analysis." ] } ], "metadata": { "esriNotebookRuntime": { "notebookRuntimeName": "ArcGIS Notebook Python 3 Standard", "notebookRuntimeVersion": "10.7.1" }, "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.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 2 }