<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 A Post-Crisis Analysis of Housing Demand
By Jason Kim
StreetEasy is New York City's leading online marketplace for real estate. It started publishing monthly time-series sales and rental data back in 2009, right after the financial crisis. We will be working with 'Median Sales Price' data in 'All Home Types', which includes information from all five boroughs.
The New York City Department of Buildings (DoB) contains the city's property records for regulation and compliance of buildings. This includes permit issuance for new building construction. We will be working with residential new buildings permit data, which includes addresses and permit issuance dates of new construction.
An analysis of StreetEasy and the Department of Buildings data will reveal trends in median prices of residential dwellings and new construction, respectively. Cross-comparing growth rates in prices and new construction can give us insights to the demand of new residential complexes and answer the question
Step1:  The following graphs show the price trends in NYC and the five boroughs. There seems to be a volatile, yet upwards trend in median sales prices in New York City. Breaking it down by boroughs reveals the following
Step2:  Calculating the percent changes between periods gives us the growth rates. We see that the Bronx, Queens, and especially Staten Island experienced the highest volatility in growth rates, which accounts for their price dips. However, Brooklyn and Manhattan had very stable, non-negative growth rates, which is probably responsible for NYC's overall stability.
Step3:  The following graphs show that Brooklyn and Queens experienced the highest levels of new residential permit issuances - consistently above 50 issuances per month. This might prove as an explanation for observed gentrification of these boroughs. However, the Bronx, Manhattan, and Staten Island have significantly lower levels of new residential permit issuances.
Step4:  Plotting the data of new residential permit issuances reveals that the growth rates remained around zero, with higher fluctuations in the Bronx and Staten Island.
<ASSISTANT_TASK:>
Python Code:
import sys                             # system module 
import pandas as pd                    # data package
import matplotlib.pyplot as plt        # graphics module  
import datetime as dt                  # date and time module
import numpy as np                     # foundation for pandas 
import re
%matplotlib inline                     
# check versions (overkill, but why not?)
print('Python version: ', sys.version)
print('Pandas version: ', pd.__version__)
print('Today: ', dt.date.today())
# Read in the StreetEasy data
url1 = 'https://raw.githubusercontent.com/codejkim/StreetEasy/master/'
url2 = 'closing_time_series_prices_All_Types_Any_Bedrooms.csv'
url = url1 + url2
se = pd.read_csv(url)
area = se.set_index('Area')
area = area.drop('Boro', 1) # Drop the columns we don't need
area = area.drop('AreaType', 1) 
boroughs = ['NYC', 'Bronx', 'Brooklyn', 'Manhattan', 'Queens', 'Staten Island']
area = area.ix[boroughs] # selects all 5 boroughs & NYC from index
areaT = area.T
Explanation: A Post-Crisis Analysis of Housing Demand
By Jason Kim
StreetEasy is New York City's leading online marketplace for real estate. It started publishing monthly time-series sales and rental data back in 2009, right after the financial crisis. We will be working with 'Median Sales Price' data in 'All Home Types', which includes information from all five boroughs.
The New York City Department of Buildings (DoB) contains the city's property records for regulation and compliance of buildings. This includes permit issuance for new building construction. We will be working with residential new buildings permit data, which includes addresses and permit issuance dates of new construction.
An analysis of StreetEasy and the Department of Buildings data will reveal trends in median prices of residential dwellings and new construction, respectively. Cross-comparing growth rates in prices and new construction can give us insights to the demand of new residential complexes and answer the question: Is new construction warranted?
End of explanation
areaT.plot(subplots = True,
          figsize = (10,15),
          title = 'Median Sales Price (in dollars)')
# Median sales price growth rate
growth = areaT.pct_change()
Explanation: The following graphs show the price trends in NYC and the five boroughs. There seems to be a volatile, yet upwards trend in median sales prices in New York City. Breaking it down by boroughs reveals the following:
* The Bronx did not perform very well after the housing crisis, shown by the downward trend and subsequent stabilization in prices.
* Brooklyn saw a high increase in prices, especially since 2014.
* Manhattan also experienced a pretty steady increase in prices.
* Queens had a large drop in prices, but appears to have bounced back since 2014.
* Starting from late 2010, when Staten Island data was available, we see high price volatility which stabilizes  after 2014.
End of explanation
growth.plot(subplots = True,
           sharey = True,
           figsize = (10,15),
           title = 'Median Sales Price Growth Rates')
# Read in the Department of Buildings data
url3 = 'New_Buildings_-Building_Permit.csv'
url4 = url1 + url3
dob = pd.read_csv(url4)
dob = dob[['Permit_Issuance_Date', 'Borough']] # Select the columns we want
dob = dob.rename(columns = {'Permit_Issuance_Date': 'Issued Date'}) # Rename column
dob['Issued Date'] = dob['Issued Date'].str.replace('0:00','') # Remove the hours/minutes time
dob['Issued Date'] = pd.to_datetime(pd.Series(dob['Issued Date'])) # Set column to datetime format
dob['Issued Date'] = dob['Issued Date'].astype(str).str[:-3] # Select Year and Month values only to group monthly new construction
dob = dob.dropna()
# Create new dataframe with grouped construction
group = dob.groupby(['Issued Date', 'Borough']).size()
grp = group.to_frame()
grp = grp.unstack()
# Select rows after 2009 (to match with StreetEasy data)
d1 = '2009-03'
d2 = '2016-12'
crisis = grp.ix[d1:d2]
Explanation: Calculating the percent changes between periods gives us the growth rates. We see that the Bronx, Queens, and especially Staten Island experienced the highest volatility in growth rates, which accounts for their price dips. However, Brooklyn and Manhattan had very stable, non-negative growth rates, which is probably responsible for NYC's overall stability.
End of explanation
crisis.plot(subplots = True,
           figsize = (15,12),
           sharey = True,
           title = 'New Permit Issuance per month')
# Permit Issuance Growth Rates
growth2 = crisis.pct_change()
Explanation: The following graphs show that Brooklyn and Queens experienced the highest levels of new residential permit issuances - consistently above 50 issuances per month. This might prove as an explanation for observed gentrification of these boroughs. However, the Bronx, Manhattan, and Staten Island have significantly lower levels of new residential permit issuances.
End of explanation
growth2.plot(subplots = True,
           figsize = (15,12),
           sharey = True,
            title = 'New Permit Issuance Growth Rates')
Explanation: Plotting the data of new residential permit issuances reveals that the growth rates remained around zero, with higher fluctuations in the Bronx and Staten Island.
End of explanation
<END_TASK>