Data Visualization - Construction permits, part 1/2¶
Overview¶
One indicator of a region's growth is the number of permits issued for new construction. Exploring and analyzing permit activity can help regional planners ensure that development occurs in accordance to the area's long-term goals. One area that has recently experienced rapid growth is Montgomery County, Maryland, a suburban county near Washington, D.C. County planners want to observe spatial and temporal growth trends, find out why certain areas are growing faster than others, and communicate key information about the county's growth to the public.
In this notebook, you'll explore Montgomery County permit data. First, you'll add the permit data from ArcGIS Living Atlas of the World. You'll explore the data and become familiar with exactly what kind of information it contains. Then, you'll analyze the data to detect patterns and find out why growth is occurring. Once you've gathered your findings from your exploration and analysis, you'll share your work online.
Explore the data¶
To better understand trends in permit activity in Montgomery County, you'll add a dataset of permits issued since 2010. Before you begin your analysis, however, it's important to explore your data and understand what it shows and does not show. You'll familiarize yourself with the data's attributes, sort the data by type, and visualize spatial and temporal trends. In doing so, you'll gain context for your analysis and know exactly which questions you still need to ask to find out why, where, and when growth is occurring.
Connect to your ArcGIS online organization.
from arcgis.gis import GIS
import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor
agol_gis = GIS()
Search for the Commercial Permits since 2010 layer. You can specify the owner's name to get more specific results. To search for content from the Living Atlas, or content shared by other users on ArcGIS Online, set outside_org=True
.
data = agol_gis.content.search('title: Commercial Permits since 2010 owner: rpeake_LearnGIS', 'Feature layer',
outside_org=True)
data[0]
Get the first item from the results.
permits = data[0]
Since the item is a Feature Layer Collection, accessing the layers property gives us a list of FeatureLayer objects. The permit layer is the first layer in this item. Visualize this layer on a map of Montgomery County, Maryland.
permit_layer = permits.layers[0]
permit_map = agol_gis.map('Montgomery County, Maryland', zoomlevel=9)
permit_map
You can add a number of different layer objects such as FeatureLayer, FeatureCollection, ImageryLayer, MapImageLayer to the map by calling the add_layer()
method.
permit_map.add_layer(permit_layer)
Data Exploration¶
Now that you've added the permit data, you'll explore its contents. Geographic data doesn't only contain information about location; it can also include other attributes not seen on a map.
Convert the layer into a spatially-enabled dataframe to explore these attributes.
permit_layer
sdf = pd.DataFrame.spatial.from_layer(permit_layer)
tail()
method gives the last 5 rows of the dataframe.
sdf.tail()
The permit data contains a long list of attributes. Some attributes have self-explanatory names, while others may have names that can be difficult to understand without context. The list of attributes can be obtained using the columns of the dataframe.
sdf.columns
sdf.describe().T
Query the types of attributes and explore the data.
sdf.dtypes
sdf['Work_Type'].unique()
sdf['Status'].unique()
sdf['Use_Code'].unique()
Permits by Status¶
The groupby()
method groups the rows per the column and does calculations, such as finding their counts, as shown in the following code.
permits_by_status = sdf.groupby(sdf['Status']).size()
permits_by_status
There are only four permit statuses: Issued, Finaled, Open, and Stop Work. To visualize the number of permits for each status, you'll create a pie chart.
Since the dataframe attributes just show the count of status, you can consider any attribute to graph the status count.
%matplotlib inline
import matplotlib.pyplot as plt
plt.axis('equal')
permits_by_status.plot(kind='pie', legend=False, label='Permits by Status');
The pie chart above shows the four permit statuses, with the size of each status determined by the number of permits. The vast majority of permits are either Issued or Finaled. Finaled permits are issued permits that have also had the requisite inspections performed.
It's helpful to visualize the spatial distribution of permit attributes on a map. You'll change the map so that each permit's symbol represents its status.
permits_by_status_map = agol_gis.map('Montgomery County, Maryland')
permits_by_status_map