Skip to content

Commit 16fe331

Browse files
authored
Merge pull request #1538 from Esri/cmpeng/find_a_home_column_names
Find_a_home.ipynb: column names subject to change by whether arcpy and fgdb
2 parents 92ef20a + 3dd0074 commit 16fe331

File tree

1 file changed

+139
-17
lines changed

1 file changed

+139
-17
lines changed

samples/04_gis_analysts_data_scientists/finding_a_new_home.ipynb

Lines changed: 139 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,23 @@
6161
"cell_type": "markdown",
6262
"metadata": {},
6363
"source": [
64-
"## Selling your home"
64+
"## Selling your home\n",
65+
"\n",
66+
"Execute the following command to install the openpyxl library if not already. This package is used to read from any Excel or CSV files.\n",
67+
"```\n",
68+
"!pip install openpyxl\n",
69+
"```"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"Also, when `matplotlib` is not present, run the following command to have it installed or upgraded:\n",
77+
"```\n",
78+
"import sys \n",
79+
"!{sys.executable} -m pip install matplotlib\n",
80+
"```"
6581
]
6682
},
6783
{
@@ -186,6 +202,44 @@
186202
"gis = GIS('home')"
187203
]
188204
},
205+
{
206+
"cell_type": "markdown",
207+
"metadata": {},
208+
"source": [
209+
"Use the boolean `has_arcpy` to flag whether `arcpy` is present on the local environement:"
210+
]
211+
},
212+
{
213+
"cell_type": "code",
214+
"execution_count": 2,
215+
"metadata": {},
216+
"outputs": [],
217+
"source": [
218+
"has_arcpy = False"
219+
]
220+
},
221+
{
222+
"cell_type": "code",
223+
"execution_count": 4,
224+
"metadata": {},
225+
"outputs": [
226+
{
227+
"name": "stdout",
228+
"output_type": "stream",
229+
"text": [
230+
"arcpy not present\n"
231+
]
232+
}
233+
],
234+
"source": [
235+
"try:\n",
236+
" import arcpy\n",
237+
" has_arcpy = True\n",
238+
" print(\"arcpy present\")\n",
239+
"except:\n",
240+
" print(\"arcpy not present\")"
241+
]
242+
},
189243
{
190244
"cell_type": "markdown",
191245
"metadata": {},
@@ -2700,6 +2754,15 @@
27002754
" tags='datascience')"
27012755
]
27022756
},
2757+
{
2758+
"cell_type": "markdown",
2759+
"metadata": {},
2760+
"source": [
2761+
"When arcpy is present, the `import_data` will upload the local SeDF (Spatially Enabled DataFrame) as a FGDB (File geodatabase) to your organization, and publish to a hosted feature layer; On the other hand, when arcpy is not present, then the `import_data` method would have the local SeDF upload to your organization as a shapefile, and then publish as a hosted Feature Layer. This minor difference will result in column/property name differences from what's defined in the original SeDF.\n",
2762+
"\n",
2763+
"The `has_arcpy` flag is to be used in determine which naming convention the newly created Feature Layer would be conforming to, when we are adding the Feature Layer for display based on variables."
2764+
]
2765+
},
27032766
{
27042767
"cell_type": "markdown",
27052768
"metadata": {},
@@ -2740,16 +2803,30 @@
27402803
"m1"
27412804
]
27422805
},
2806+
{
2807+
"cell_type": "code",
2808+
"execution_count": 6,
2809+
"metadata": {},
2810+
"outputs": [],
2811+
"source": [
2812+
"cur_field_name = \"BuyerSellerIndex\"\n",
2813+
"if has_arcpy:\n",
2814+
" if cur_field_name not in mergd_lyr.layers[0].properties.fields:\n",
2815+
" cur_field_name = \"buyer_seller_index\"\n",
2816+
"else:\n",
2817+
" cur_field_name = \"BuyerSelle\""
2818+
]
2819+
},
27432820
{
27442821
"cell_type": "code",
27452822
"execution_count": 68,
27462823
"metadata": {},
27472824
"outputs": [],
27482825
"source": [
27492826
"m1.add_layer(mergd_lyr, {\"renderer\":\"ClassedColorRenderer\",\n",
2750-
" \"field_name\":\"BuyerSellerIndex\",\n",
2827+
" \"field_name\":cur_field_name,\n",
27512828
" \"opacity\":0.7\n",
2752-
" })"
2829+
" })"
27532830
]
27542831
},
27552832
{
@@ -2785,14 +2862,28 @@
27852862
"m2"
27862863
]
27872864
},
2865+
{
2866+
"cell_type": "code",
2867+
"execution_count": 7,
2868+
"metadata": {},
2869+
"outputs": [],
2870+
"source": [
2871+
"cur_field_name = \"DaysOnMarket\"\n",
2872+
"if has_arcpy:\n",
2873+
" if cur_field_name not in mergd_lyr.layers[0].properties.fields:\n",
2874+
" cur_field_name = \"days_on_market\"\n",
2875+
"else:\n",
2876+
" cur_field_name = \"DaysOnMark\""
2877+
]
2878+
},
27882879
{
27892880
"cell_type": "code",
27902881
"execution_count": 70,
27912882
"metadata": {},
27922883
"outputs": [],
27932884
"source": [
27942885
"m2.add_layer(mergd_lyr, {\"renderer\":\"ClassedSizeRenderer\",\n",
2795-
" \"field_name\":\"DaysOnMarket\",\n",
2886+
" \"field_name\":cur_field_name,\n",
27962887
" \"opacity\":0.7\n",
27972888
" })"
27982889
]
@@ -4222,17 +4313,31 @@
42224313
"m4"
42234314
]
42244315
},
4316+
{
4317+
"cell_type": "code",
4318+
"execution_count": 8,
4319+
"metadata": {},
4320+
"outputs": [],
4321+
"source": [
4322+
"cur_field_name = \"MarketHealthIndex\"\n",
4323+
"if cur_field_name not in hlth_lyr.layers[0].properties.fields:\n",
4324+
" if has_arcpy:\n",
4325+
" cur_field_name = \"market_health_index\"\n",
4326+
" else:\n",
4327+
" cur_field_name = \"MarketHeal\""
4328+
]
4329+
},
42254330
{
42264331
"cell_type": "code",
42274332
"execution_count": 104,
42284333
"metadata": {},
42294334
"outputs": [],
42304335
"source": [
42314336
"m4.add_layer(hlth_lyr, {\"renderer\":\"ClassedColorRenderer\",\n",
4232-
" \"field_name\":\"MarketHealthIndex\",\n",
4337+
" \"field_name\":cur_field_name,\n",
42334338
" \"classificationMethod\":'quantile',\n",
4234-
" \"opacity\":0.7\n",
4235-
" })"
4339+
" \"opacity\":0.7\n",
4340+
" })"
42364341
]
42374342
},
42384343
{
@@ -4398,10 +4503,10 @@
43984503
"outputs": [],
43994504
"source": [
44004505
"m5.add_layer(hlth_lyr, {\"renderer\":\"ClassedColorRenderer\",\n",
4401-
" \"field_name\":\"MarketHealthIndex\",\n",
4506+
" \"field_name\":cur_field_name,\n",
44024507
" \"classificationMethod\":'quantile',\n",
4403-
" \"opacity\":0.7\n",
4404-
" })\n",
4508+
" \"opacity\":0.7\n",
4509+
" })\n",
44054510
"m5.add_layer(drive_time_lyr)"
44064511
]
44074512
},
@@ -4451,9 +4556,9 @@
44514556
"metadata": {},
44524557
"outputs": [],
44534558
"source": [
4454-
"m6.add_layer(hlth_lyr, {\"renderer\":\"ClassedColorRenderer\",\n",
4559+
"m6.add_layer(hlth_lyr, { \"renderer\":\"ClassedColorRenderer\",\n",
44554560
" \"field_name\":\"ZHVI\",\n",
4456-
" \"classificationMethod\":'quantile',\n",
4561+
" \"classificationMethod\":'quantile',\n",
44574562
" \"opacity\":0.7\n",
44584563
" })\n",
44594564
"m6.add_layer(drive_time_lyr)"
@@ -4499,16 +4604,30 @@
44994604
"m7"
45004605
]
45014606
},
4607+
{
4608+
"cell_type": "code",
4609+
"execution_count": 10,
4610+
"metadata": {},
4611+
"outputs": [],
4612+
"source": [
4613+
"cur_field_name2 = \"ForecastYoYPctChange\"\n",
4614+
"if cur_field_name2 not in hlth_lyr.layers[0].properties.fields:\n",
4615+
" if has_arcpy:\n",
4616+
" cur_field_name2 = \"forecast_yo_y_pct_change\"\n",
4617+
" else:\n",
4618+
" cur_field_name2 = \"ForecastYo\""
4619+
]
4620+
},
45024621
{
45034622
"cell_type": "code",
45044623
"execution_count": 119,
45054624
"metadata": {},
45064625
"outputs": [],
45074626
"source": [
45084627
"m7.add_layer(hlth_lyr, {\"renderer\":\"ClassedColorRenderer\",\n",
4509-
" \"field_name\":\"ForecastYoYPctChange\",\n",
4628+
" \"field_name\":cur_field_name2,\n",
45104629
" \"classificationMethod\":'quantile',\n",
4511-
" \"opacity\":0.7\n",
4630+
" \"opacity\":0.7\n",
45124631
" })\n",
45134632
"m7.add_layer(drive_time_lyr)"
45144633
]
@@ -4855,7 +4974,10 @@
48554974
}
48564975
],
48574976
"source": [
4858-
"zip_hlth_intersect.query(where='((ZHVI > 350000) AND (ZHVI < 600000) AND (MarketHealthIndex > 8) AND (ForecastYoYPctChange> 0.06)) AND (1=1)').sdf"
4977+
"query_str = '((ZHVI > 350000) AND (ZHVI < 600000) AND (' + cur_field_name + ' > 8) AND (' + cur_field_name2 + '> 0.06)) AND (1=1)'\n",
4978+
"\n",
4979+
"zip_hlth_intersect_df = zip_hlth_intersect.query(where=query_str).sdf\n",
4980+
"zip_hlth_intersect_df"
48594981
]
48604982
},
48614983
{
@@ -4891,7 +5013,7 @@
48915013
"outputs": [],
48925014
"source": [
48935015
"m9.add_layer(zip_hlth_intersect,\n",
4894-
" {\"definition_expression\": '((ZHVI > 350000) AND (ZHVI < 600000) AND (MarketHealthIndex > 8) AND (ForecastYoYPctChange > 0.06)) AND (1=1)',\n",
5016+
" {\"definition_expression\": query_str,\n",
48955017
" \"classificationMethod\":'quantile'})\n",
48965018
"m9.zoom_to_layer(zip_hlth_intersect)"
48975019
]
@@ -4938,7 +5060,7 @@
49385060
"name": "python",
49395061
"nbconvert_exporter": "python",
49405062
"pygments_lexer": "ipython3",
4941-
"version": "3.9.15"
5063+
"version": "3.9.16"
49425064
}
49435065
},
49445066
"nbformat": 4,

0 commit comments

Comments
 (0)