On the city of Saint Paul Data Portal, there is information on the number of current vacant buildings in Saint Paul. You can download the data from here. If a building is occupied, then it will be removed for the list. Thus there will be more vacant houses within the last 2 to 3 years. The number of vacant properties can provide concern for a community but also an opportunity to revitalize an area. Classic example of urban blight is when many commercial fronts have closed down, which impacts development nearby. Vacant/abandoned properties, for better or for worse could provides a space space for illicit activities or it can provide housing for the homeless and downtrodden.
With this report, I hope residents can find areas that need more resources (i.e. economic development and housing resources) and consider options in dealing with the looming housing.
This dataset contains all of the registered vacant buildings in the City, as well as their type, and Vacant Building Category.
df.head(2)
Address | VacantDate | Dwelling | Vacant_Building_Category | Ward | District | Census_Tract | Coordinates | DistrictCouncilMap | CouncilWard | Gunk1 | Gunk2 | Latitude | Longitude | Datetime | Year | Date | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 937 SHERBURNE AVE | 04/30/2019 12:00:00 AM | Duplex | 2 | 1.0 | 7.0 | 32500.0 | (44.9567603300828, -93.139762414751) | 10.0 | 7.0 | 55.0 | 47.0 | 44.95676 | -93.139762 | 2019-04-30 | 2019 | 2019-04-30 |
1 | 535 FOREST ST | 04/26/2019 12:00:00 AM | Single Family Residential | 2 | 7.0 | 4.0 | 34500.0 | (44.957410404869, -93.061161243197) | 15.0 | 2.0 | 196.0 | 42.0 | 44.95741 | -93.061161 | 2019-04-26 | 2019 | 2019-04-26 |
plt.figure(figsize=(10,6))
sns.set_style("darkgrid") #white, white-grid, ticks
sns.distplot(df['Year'], kde=False).set_title("Current Vacant Buildings by Year of Vacancy")
Text(0.5, 1.0, 'Current Vacant Buildings by Year of Vacancy')
print(df['Dwelling'].value_counts().sort_index(level=1))
Commercial 65 Duplex 86 Mixed Use 7 Multi-family Residential 17 Single Family Residential 322 Name: Dwelling, dtype: int64
plt.figure(figsize=(10,6))
sns.distplot(df['District'], bins=17, vertical=True, kde=False).set_title("Current Vacant Buildings by District Council")
Text(0.5, 1.0, 'Current Vacant Buildings by District Council')
barplot('District',12,9)
plt.figure(figsize=(10,6))
sns.distplot(df['Ward'], bins=17, vertical=True, kde=False).set_title("Current Vacant Buildings by Ward Grid")
Text(0.5, 1.0, 'Current Vacant Buildings by Ward Grid')
plt.figure(figsize=(10,6))
barplot('Ward',7,7)
<Figure size 720x432 with 0 Axes>
CLick on dots to get more information; please zoom in
Legend: Vacant Year Range
map_Vacancy_byYear()
Legend: Dwelling Type
map_Vacancy_TypeWard()
Legend: Dwelling Type
map_Vacancy_TypeDistrict(7)
Legend: Dwelling Type
map_Vacancy_TypeWard(1)
Green: Hotspot of at least 8 crimes or more
Orange: Vacant buildings
Note: The Crime Dataset is clean from Frogtown Map Project. This was my first attempt of combining to different datasets together in a map
Map_Frogtown_VacantBuilding_Crime_Current()
There are some neighborhoods with clusters of vacant buildings. How should the community deal with this? how should revitalize look like? Is there a correlation between hotspots and vacant buildings? Feel free to explore.
df.iloc[:,4:]
address | census_tract | district | dwelling_type | map_location | sale_review_category | vacant_as_of | ward | |
---|---|---|---|---|---|---|---|---|
0 | 937 SHERBURNE AVE | 32500 | 7 | Duplex | {'latitude': '44.9567603300828', 'longitude': ... | 2 | 2019-04-30T00:00:00.000 | 1 |
1 | 535 FOREST ST | 34500 | 4 | Single Family Residential | {'latitude': '44.957410404869', 'longitude': '... | 2 | 2019-04-26T00:00:00.000 | 7 |
2 | 842 UNIVERSITY AVE W | 33500 | 8 | Single Family Residential | {'latitude': '44.9554819820147', 'longitude': ... | 2 | 2019-04-24T00:00:00.000 | 1 |
3 | 996 MARION ST | 30800 | 6 | Duplex | {'latitude': '44.97139072308', 'longitude': '-... | 1 | 2019-04-24T00:00:00.000 | 5 |
4 | 652 HALL AVE | 37200 | 3 | Duplex | {'latitude': '44.9263735950436', 'longitude': ... | 3 | 2019-04-22T00:00:00.000 | 2 |
5 | 792 DULUTH ST | 31701 | 4 | Duplex | {'latitude': '44.965291417806', 'longitude': '... | 2 | 2019-04-22T00:00:00.000 | 6 |
6 | 1400 UNIVERSITY AVE W | 33400 | 13 | Commercial | {'latitude': '44.9536084165855', 'longitude': ... | 2 | 2019-04-16T00:00:00.000 | 1 |
7 | 425 RICE ST | 33700 | 17 | Commercial | {'latitude': '44.9536181436373', 'longitude': ... | 2 | 2019-04-16T00:00:00.000 | 1 |
8 | 1440 MARSHALL AVE | 33400 | 13 | Commercial | {'latitude': '44.9482026685217', 'longitude': ... | 2 | 2019-04-10T00:00:00.000 | 1 |
9 | 218 PASCAL ST N | 33400 | 13 | Commercial | {'latitude': '44.9478738971447', 'longitude': ... | 2 | 2019-04-10T00:00:00.000 | 1 |
10 | 1876 MECHANIC AVE | 31801 | 2 | Single Family Residential | {'latitude': '44.9728379377429', 'longitude': ... | 1 | 2019-04-09T00:00:00.000 | 6 |
11 | 750 CHATSWORTH ST S | 36700 | 9 | Duplex | {'latitude': '44.9189407406274', 'longitude': ... | 2 | 2019-04-05T00:00:00.000 | 2 |
12 | 610 LARPENTEUR AVE E | 30602 | 5 | Duplex | {'latitude': '44.9917519986127', 'longitude': ... | 2 | 2019-04-03T00:00:00.000 | 6 |
13 | 25 JESSAMINE AVE E | 30500 | 6 | Single Family Residential | {'latitude': '44.9748357438782', 'longitude': ... | 2 | 2019-04-03T00:00:00.000 | 5 |
14 | 1739 CARROLL AVE | 33400 | 13 | Single Family Residential | {'latitude': '44.9505108931445', 'longitude': ... | 2 | 2019-04-03T00:00:00.000 | 4 |
15 | 1271 MARION ST | 30800 | 6 | Single Family Residential | {'latitude': '44.9795463927248', 'longitude': ... | 1 | 2019-04-01T00:00:00.000 | 5 |
16 | 240 COTTAGE AVE W | 30400 | 6 | Single Family Residential | {'latitude': '44.9826352633946', 'longitude': ... | 2 | 2019-03-25T00:00:00.000 | 5 |
17 | 1156 MARYLAND AVE E | 31100 | 5 | Single Family Residential | {'latitude': '44.9773487291127', 'longitude': ... | 2 | 2019-03-22T00:00:00.000 | 6 |
18 | 598 LAFOND AVE | 32600 | 7 | Single Family Residential | {'latitude': '44.9601196977974', 'longitude': ... | 2 | 2019-03-21T00:00:00.000 | 1 |
19 | 1734 7TH ST E | 31801 | 2 | Single Family Residential | {'latitude': '44.9664939992909', 'longitude': ... | 2 | 2019-03-21T00:00:00.000 | 7 |
20 | 1403 HAMLINE AVE N | 30201 | 10 | Single Family Residential | {'latitude': '44.9834949793758', 'longitude': ... | 1 | 2019-03-21T00:00:00.000 | 4 |
21 | 65 WINIFRED ST W | 37100 | 3 | Single Family Residential | {'latitude': '44.9316620044322', 'longitude': ... | 1 | 2019-03-19T00:00:00.000 | 2 |
22 | 1155 MARION ST | 30800 | 6 | Single Family Residential | {'latitude': '44.9759788153959', 'longitude': ... | 2 | 2019-03-19T00:00:00.000 | 5 |
23 | 941 CYPRESS ST | 31600 | 5 | Single Family Residential | {'latitude': '44.9697655636952', 'longitude': ... | 2 | 2019-03-14T00:00:00.000 | 6 |
24 | 1311 BURNS AVE | 34601 | 4 | Single Family Residential | {'latitude': '44.9488932778155', 'longitude': ... | 1 | 2019-03-14T00:00:00.000 | 7 |
25 | 817 BURR ST | 31500 | 5 | Multi-family Residential | {'latitude': '44.965869347891', 'longitude': '... | 2 | 2019-03-13T00:00:00.000 | 5 |
26 | 1144 FAIRMOUNT AVE | 35300 | 16 | Single Family Residential | {'latitude': '44.9366493090143', 'longitude': ... | 2 | 2019-03-13T00:00:00.000 | 2 |
27 | 2039 CASE AVE | 31802 | 2 | Single Family Residential | {'latitude': '44.9704609360422', 'longitude': ... | 1 | 2019-03-05T00:00:00.000 | 6 |
28 | 1241 6TH ST E | 34601 | 4 | Duplex | {'latitude': '44.9605260318585', 'longitude': ... | 2 | 2019-03-05T00:00:00.000 | 7 |
29 | 2060 3RD ST E | 34702 | 1 | Single Family Residential | {'latitude': '44.9565683001788', 'longitude': ... | 1 | 2019-03-05T00:00:00.000 | 7 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
507 | 1313 SEMINARY AVE | 32300 | 11 | Single Family Residential | {'latitude': '44.964887859907', 'longitude': '... | 2 | 2008-06-05T00:00:00.000 | 4 |
508 | 474 CURTICE ST E | 37200 | 3 | Single Family Residential | {'latitude': '44.922858156184', 'longitude': '... | 2 | 2008-03-29T00:00:00.000 | 2 |
509 | 1020 CARROLL AVE | 33800 | 8 | Single Family Residential | {'latitude': '44.9501237852992', 'longitude': ... | 2 | 2008-03-12T00:00:00.000 | 1 |
510 | 50 FILLMORE AVE E | 37100 | 3 | Commercial | {'latitude': '44.9402142051823', 'longitude': ... | 2 | 2008-02-26T00:00:00.000 | 2 |
511 | 822 VAN BUREN AVE | 32400 | 7 | Duplex | {'latitude': '44.9619119910923', 'longitude': ... | 2 | 2007-11-28T00:00:00.000 | 1 |
512 | 575 PARK ST | 42800 | 7 | Single Family Residential | {'latitude': '44.9586747280584', 'longitude': ... | 2 | 2007-11-13T00:00:00.000 | 1 |
513 | 383 KING ST W | 37000 | 3 | Multi-family Residential | {'latitude': '44.9276700931864', 'longitude': ... | 2 | 2007-08-23T00:00:00.000 | 2 |
514 | 1626 ENGLEWOOD AVE | 32100 | 11 | Multi-family Residential | {'latitude': '44.9638769363282', 'longitude': ... | 2 | 2007-08-16T00:00:00.000 | 4 |
515 | 1093 4TH ST E | 34601 | 4 | Single Family Residential | {'latitude': '44.9588922296321', 'longitude': ... | 2 | 2007-07-20T00:00:00.000 | 7 |
516 | 287 AVON ST N | 33800 | 8 | Duplex | {'latitude': '44.9499427190014', 'longitude': ... | 2 | 2007-07-17T00:00:00.000 | 1 |
517 | 1904 PRINCETON AVE | 35100 | 14 | Single Family Residential | {'latitude': '44.9359488142281', 'longitude': ... | 2 | 2007-07-12T00:00:00.000 | 3 |
518 | 55 MANITOBA AVE | 31400 | 6 | Duplex | {'latitude': '44.9684623676033', 'longitude': ... | 2 | 2007-06-01T00:00:00.000 | 1 |
519 | 889 AGATE ST | 31400 | 6 | Multi-family Residential | {'latitude': '44.9680024783713', 'longitude': ... | 2 | 2007-06-01T00:00:00.000 | 5 |
520 | 380 RANDOLPH AVE | 36000 | 9 | Commercial | {'latitude': '44.9267151217236', 'longitude': ... | 2 | 2006-11-21T00:00:00.000 | 2 |
521 | 811 4TH ST E | 34500 | 4 | Single Family Residential | {'latitude': '44.9582234042631', 'longitude': ... | 2 | 2006-10-30T00:00:00.000 | 7 |
522 | 667 OHIO ST | 37000 | 3 | Single Family Residential | {'latitude': '44.9259319976014', 'longitude': ... | 3 | 2006-05-26T00:00:00.000 | 2 |
523 | 716 WILSON AVE | 34400 | 4 | Single Family Residential | {'latitude': '44.9532960197741', 'longitude': ... | 2 | 2005-10-27T00:00:00.000 | 7 |
524 | 587 COOK AVE E | 31000 | 5 | Duplex | {'latitude': '44.9730483353299', 'longitude': ... | 2 | 2005-10-14T00:00:00.000 | 6 |
525 | 680 MINNEHAHA AVE E BLDG 3 | NaN | NaN | Multi-family Residential | NaN | 2 | 2005-07-21T00:00:00.000 | NaN |
526 | 650 AURORA AVE | 33500 | 8 | Single Family Residential | {'latitude': '44.9546496376062', 'longitude': ... | 3 | 2005-01-07T00:00:00.000 | 1 |
527 | 1023 JESSIE ST | 30900 | 5 | Duplex | {'latitude': '44.9721671763833', 'longitude': ... | 2 | 2004-12-09T00:00:00.000 | 5 |
528 | 2075 SCUDDER ST | 30100 | 12 | Single Family Residential | {'latitude': '44.9787618089353', 'longitude': ... | 2 | 2004-08-05T00:00:00.000 | 4 |
529 | 1253 CLEVELAND AVE N | 30100 | 12 | Single Family Residential | {'latitude': '44.9787614519552', 'longitude': ... | 2 | 2004-08-05T00:00:00.000 | 4 |
530 | 1508 COMO AVE | 30201 | 10 | Duplex | {'latitude': '44.977126870947', 'longitude': '... | 2 | 2003-07-29T00:00:00.000 | 4 |
531 | 2062 COMO AVE | 30100 | 12 | Single Family Residential | {'latitude': '44.9769023417819', 'longitude': ... | 2 | 2001-11-09T00:00:00.000 | 4 |
532 | 1308 VICTORIA ST N | 30300 | 10 | Single Family Residential | {'latitude': '44.9806018151037', 'longitude': ... | 2 | 2001-10-30T00:00:00.000 | 5 |
533 | 466 LAUREL AVE | 35500 | 8 | Single Family Residential | {'latitude': '44.9452343913786', 'longitude': ... | 3 | 2000-05-03T00:00:00.000 | 1 |
534 | 847 HUDSON ROAD | 34400 | 4 | Commercial | {'latitude': '44.9523831474725', 'longitude': ... | 3 | 1999-08-10T00:00:00.000 | 7 |
535 | 395 MICHIGAN ST | 36900 | 9 | Single Family Residential | {'latitude': '44.9352600297476', 'longitude': ... | 3 | 1996-05-15T00:00:00.000 | 2 |
536 | 365 MICHIGAN ST | 36000 | 9 | Single Family Residential | {'latitude': '44.9349513001028', 'longitude': ... | 2 | 1995-07-12T00:00:00.000 | 2 |
537 rows × 8 columns
import pandas as pd
from sodapy import Socrata
#New Upload Method Get Information from Socrata API
client = Socrata("information.stpaul.gov", None)
results = client.get("fgbn-288b", limit=1000000)
df = pd.DataFrame.from_records(results)
# Remove meanigless first foour columns
df=df.iloc[:,4:]
#Set up columns and data types
cols= ['Address','Census_Tract','District','Dwelling','Coordinates','Vacant_Building_Category','VacantDate', 'Ward']
df.columns= cols
df = df.astype({"District": float, "Vacant_Building_Category": int, "Ward":float, "Census_Tract":float})
df.head(2)
#df.columns= cols
WARNING:root:Requests made without an app_token will be subject to strict throttling limits.
Address | Census_Tract | District | Dwelling | Coordinates | Vacant_Building_Category | VacantDate | Ward | |
---|---|---|---|---|---|---|---|---|
0 | 398 TOTEM ROAD | 37403.0 | 1.0 | Multi-family Residential | {'latitude': '44.925292830328', 'longitude': '... | 1 | 2019-11-25T00:00:00.000 | 7.0 |
1 | 1971 NORTONIA AVE | 31802.0 | 2.0 | Duplex | {'latitude': '44.9650944591901', 'longitude': ... | 2 | 2019-11-22T00:00:00.000 | 7.0 |
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import warnings
warnings.filterwarnings('ignore')
import seaborn as sns
import scipy.stats as stats #used to get correlation coefficient
import folium
import pandas as pd
from sodapy import Socrata
#New Upload Method Get Information from Socrata API
client = Socrata("information.stpaul.gov", None)
results = client.get("fgbn-288b", limit=1000000)
df = pd.DataFrame.from_records(results)
# Remove meanigless first foour columns
df=df.iloc[:,4:]
#Set up columns and data types
cols= ['Address','Census_Tract','District','Dwelling','Coordinates','Vacant_Building_Category','VacantDate', 'Ward']
df.columns= cols
df = df.astype({"District": float, "Vacant_Building_Category": int, "Ward":float, "Census_Tract":float})
#load data
#df = pd.read_csv('Data/Vacant_Buildings_-_Dataset.csv')
#cols= ['Address','VacantDate','Dwelling','Vacant_Building_Category','Ward','District','Census_Tract','Coordinates','DistrictCouncilMap','CouncilWard','Gunk1','Gunk2']
#df.columns= cols
# Get Coordinates by converting to string
df['Coordinates'] = df['Coordinates'].astype('str')
new=df['Coordinates'].str.split("', '", n = 1, expand = True)
# get Latitude:
lat=new[0].str.split(" '", n = 1, expand = True)
df['Latitude']= pd.to_numeric(lat[1])
#Get Longtitude
new= new[1].str.split("', '", n = 1, expand = True)
long=new[0].str.split(" '", n = 1, expand = True)
df['Longitude']= pd.to_numeric(long[1])
# Get Year and Date Variable
df['Datetime']= pd.to_datetime(df['VacantDate'])
df['Year']=df['Datetime'].dt.year
df['Date']=pd.to_datetime(df['Datetime']).apply(lambda x: x.date())
df=df.query('Latitude != "NaN"')
def map_Vacancy_byYear():
# generate a new map
FG_map = folium.Map(location=[44.9608901, -93.1010336], zoom_start=12,tiles="OpenStreetMap")
#setup
Index =['Address','Date','Dwelling', 'Ward','District','Latitude','Longitude','Year']
B=df[Index]
T=B.query('Year <= 2012')
V=B.query('Year > 2012 and Year < 2016')
N=B.query('Year == 2016')
A=B.query('Year == 2017')
D=B.query('Year in (2018,2019)')
for index, row in T.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color= "#FF0000", #red
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in V.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#E37222", #orange
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in N.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#654321", #brown
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in A.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#0000ff", #blue
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in D.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color='#007849', #green
popup=popup_text,
fill=True).add_to(FG_map)
return FG_map
def map_Vacancy_TypeDistrict(Dis='All'):
# generate a new map
FG_map = folium.Map(location=[44.958326, -93.122926], zoom_start=14,tiles="OpenStreetMap")
#setup
Index =['Address','Date','Dwelling', 'Ward','District','Latitude','Longitude','Year']
if Dis=='All':
B=df
else:
B=df[(df['District']==Dis)]
B=B[Index]
T=B.query('Dwelling == "Mixed Use"')
V=B.query('Dwelling=="Duplex"')
N=B.query('Dwelling == "Commerical"')
A=B.query('Dwelling == "Multi-family Residential"')
D=B.query('Dwelling == "Single Family Residential"')
#Create Frogtown GeoMap
FG_map = folium.Map(location=[44.958326, -93.122926], zoom_start=14,tiles="OpenStreetMap")
for index, row in T.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color= "#FF0000", #red
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in V.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#E37222", #orange
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in N.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#654321", #brown
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in A.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#0000ff", #blue
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in D.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color='#007849', #green
popup=popup_text,
fill=True).add_to(FG_map)
return FG_map
def map_Vacancy_TypeWard(War='All'):
# generate a new map
FG_map = folium.Map(location=[44.958326, -93.122926], zoom_start=12,tiles="OpenStreetMap")
#setup
Index =['Address','Date','Dwelling', 'Ward','District','Latitude','Longitude','Year']
if War=='All':
B=df
else:
B=df[(df['Ward']==War)]
B=B[Index]
T=B.query('Dwelling == "Mixed Use"')
V=B.query('Dwelling=="Duplex"')
N=B.query('Dwelling == "Commerical"')
A=B.query('Dwelling == "Multi-family Residential"')
D=B.query('Dwelling == "Single Family Residential"')
#Create Frogtown GeoMap
FG_map = folium.Map(location=[44.958326, -93.122926], zoom_start=14,tiles="OpenStreetMap")
for index, row in T.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color= "#FF0000", #red
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in V.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#E37222", #orange
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in N.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#654321", #brown
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in A.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#0000ff", #blue
popup=popup_text,
fill=True).add_to(FG_map)
for index, row in D.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color='#007849', #green
popup=popup_text,
fill=True).add_to(FG_map)
return FG_map
def barplot(Var1,fig1,fig2):
plt.figure(figsize=(fig1,fig2))
A= df.groupby([Var1,'Dwelling']).count().sort_index(level=1)
A=A.reset_index()
A= A.query('Dwelling not in ("Mixed Use", "Multi-family Residential")')
ax = sns.barplot(x="Date", y=Var1, hue="Dwelling", data=A, orient= 'h').set_title('Vacant Dwellings by {}'.format(Var1))
plt.xlabel('')
return plt.show()
WARNING:root:Requests made without an app_token will be subject to strict throttling limits.
#Upload Data
fg = pd.read_csv('Data/FGCrime_Final.csv')
#Set max limit for uptodate function
Max= fg.loc[1,'Day_Max']
# Set a friendly Date variable
fg['FDate']=fg['Month'].astype(str) + '/' + fg['Day'].astype(str) + '/'
fgp= fg.query('Code in [9954]') # Specify proactive calls
fgc= fg.query('Code not in [9954,9959]') #specify all crime related police visits
fgc_Date= fgc[(fgc['DayYear'] <= Max)] #this specifies to date df
def Map_Frogtown_VacantBuilding_Crime_Current():
# generate a new map
FG_map = folium.Map(location=[44.958326, -93.122926], zoom_start=14,tiles="OpenStreetMap")
#setup
Bl= fgc[(fgc['Year'] > 2017)]
Index =['Block','Latitude','Longitude', 'Count','Theft','Vandalism','Narcotics','Auto Theft','Burglary','Discharge'\
,'Robbery','Domestic Assault','Violent','Arson']
BM=Bl.query('LateNight ==0')
BM=BM[Index].groupby(['Block','Latitude','Longitude']).sum().reset_index()
BM=BM.query('Count>7')
# for each row in the data, add a cicle marker
for index, row in BM.iterrows():
popup_text = "Year: 2018-19 <br> Address: {}<br> total incidents: {}<br> Theft: {}<br> Vandalism: {}\
<br> Narcotics: {}<br> Auto Theft: {}<br> Burglary: {}<br> Discharge: {}<br> Robbery: {}\
<br> Domestic Assault: {}<br> Violent: {}<br> Arson: {}"
popup_text = popup_text.format(row["Block"], row['Count'], row['Theft'], row['Vandalism'], row['Robbery'],\
row['Auto Theft'], row['Burglary'], row['Discharge'], row['Domestic Assault'],\
row['Domestic Assault'],row['Violent'],row['Arson'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=row['Count']/2,
color="#007849", #green
popup=popup_text,
fill=True).add_to(FG_map)
Index1 =['Address','Date','Dwelling', 'Ward','District','Latitude','Longitude','Year']
B=df[(df['Ward']==1)]
B=B[Index1]
for index, row in B.iterrows():
popup_text = "Address: {}<br>District: {}<br>Ward: {}<br> Date: {}<br> Dwelling:{}"
popup_text = popup_text.format(row["Address"],row['District'],row['Ward'],row['Date'],row['Dwelling'])
folium.CircleMarker(location=(row["Latitude"],row["Longitude"]),
radius=5,
color="#E37222", #orange
popup=popup_text,
fill=True).add_to(FG_map)
return FG_map