Data Summarization - Construction permits, part 2/2¶
Table of Contents
In the "Explore and analyze construction permits" notebook, we explored your data and learned a little about the spatial and temporal trends of permit activity in Montgomery County. In this lesson, we'll move beyond exploration and run spatial analysis tools to answer specific questions that can't be answered by the data itself. In particular, we want to know why permits spiked in Germantown in 2011 and predict where future permit spikes - and, by extension, future growth - are likely to occur.
First, we'll aggregate the points by ZIP Code. We'll enrich each ZIP Code with demographic information and learn more about the demographic conditions that led to such rapid growth in such a short time. Once you determine why growth occurred where and when it did, we'll locate other ZIP Codes with similar demographic characteristics to predict future growth.
Aggregate points¶
from arcgis import GIS
gis = GIS('home')
data = gis.content.search("Commercial_Permits_since_2010 owner:api_data_owner",
'Feature layer',
outside_org=True)
data[0]
permits = data[0]
permit_layer = permits.layers[0]
zip_code = gis.content.search('title:ZIP Code Boundaries 2017 owner:esri_dm', 'Feature layer',
outside_org=True)
zip_code[0]
zip_item = zip_code[0]
The USA_ZIP_Code layer is added as a new item. Since the item is a feature layer collection, using the layers property will give us a list of layers.
for lyr in zip_item.layers:
print(lyr.properties.name)
zip_code_layer = zip_item.layers[3]
Next, you'll use this layer to aggregate permit points. By default, the parameters are set to use the ZIP Codes as the area layer, the permits as the layer to be aggregated, and the layer style to be based on permit count. These parameters are exactly what you want.
from arcgis.features.summarize_data import aggregate_points
from datetime import datetime as dt
permit_agg_by_zip = aggregate_points(permit_layer, zip_code_layer,
keep_boundaries_with_no_points=False,
output_name='zipcode_aggregate' + str(dt.now().microsecond))
permit_agg_by_zip
Aggregation results¶
agg_map = gis.map('Maryland')
agg_map
agg_map.add_layer(permit_agg_by_zip)
The new layer looks like a point layer, but it's actually a polygon layer with a point symbology. Each point represents the number of permits per ZIP Code area. Larger points indicate ZIP Codes with more permits.
import pandas as pd
sdf = pd.DataFrame.spatial.from_layer(permit_agg_by_zip.layers[0])
sdf.head(10)
sdf.reset_index(inplace=True)
sdf.head()
Review some basic statistics about the data.
sdf['Point_Count'].mean()
sdf['Point_Count'].max()
sdf['Point_Count'].min()
agg_layer = permit_agg_by_zip.layers[0]
Although most of the large point symbols on the map are in the southeast corner, near Washington, D.C., there are a few large points in the northwest. In particular, there is a very large circle in the ZIP Code located in Clarksburg. (If you're using different ZIP Code data, this area may be identified as ZIP Code 20871 instead.) The ZIP code has 948 permits. Additionally, this area geographically corresponds to the hot spot you identified in the previous lesson. This ZIP Code is one that you'll focus on when you enrich your layer with demographic data.
Enrich the data¶
Are there demographic characteristics about the Clarksburg ZIP Code that contributed to its high growth? If so, are there other areas with those characteristics that may experience growth in the future? To answer these questions, you'll use the Enrich Data analysis tool. This tool adds demographic attributes of your choice to your data. Specifically, you'll add Tapestry information to each ZIP Code. Tapestry is a summary of many demographic and socioeconomic variables, including age groups and lifestyle choices. It'll teach you more about the types of people who live in your area of interest and help you better understand the reasons why growth happened where it did.
from arcgis.features.enrich_data import enrich_layer
enrich_aggregate = enrich_layer(agg_layer,
analysis_variables=["AtRisk.TSEGNAME"],
output_name="added_tapestry_var" + str(dt.now().microsecond))
enrich_aggregate
agg_lyr = enrich_aggregate.layers[0]
sdf = pd.DataFrame.spatial.from_layer(agg_lyr)
sdf.head()
enrich_aggregate_map = gis.map('Maryland')
enrich_aggregate_map