<jupyter_start><jupyter_text>For this project I will be analyzing 911 call data from a [Kaggle dataset](https://www.kaggle.com/mchirico/montcoalert), uploaded by <NAME>. This dataset contains 911 calls from Montgomery County, Pennsylvania.Columns in the dataset:* lat : String variable (Latitude)* lng: String variable (Longitude)* desc: String variable (Description of the Emergency Call)* zip: String variable (Zipcode)* title: String variable (Title)* timeStamp: String variable (Time of call)* twp: String variable (Township)* addr: String variable (Address)* e: String variable (Dummy variable)  Data and Setup<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
sb.set_style('whitegrid')
%matplotlib inline
calls = pd.read_csv('911.csv')
calls.info()
calls.head(5)<jupyter_output><empty_output><jupyter_text>** Create a new column called Call Reason to split up the 911 calls by type of emergency (EMS, traffic, and fire)**** The title for each call has a type of emergency followed by a colon and the title code, so I used a .split() on the colons to get the department name for each call **<jupyter_code>calls['Call Reason'] = calls['title'].apply(lambda title: title.split(':')[0])<jupyter_output><empty_output><jupyter_text>** Count for each call reason **<jupyter_code>calls['Call Reason'].value_counts()<jupyter_output><empty_output><jupyter_text>** Plot with the value counts displayed for each type of emergency **<jupyter_code>sb.countplot(x='Call Reason',data=calls,palette='viridis')
type(calls['timeStamp'].iloc[0])<jupyter_output><empty_output><jupyter_text>** The timeStamp column is a string type so it must be converted to a datetime object in order to perform some analysis on it **<jupyter_code>calls['timeStamp'] = pd.to_datetime(calls['timeStamp'])
calls['Hours'] = calls['timeStamp'].apply(lambda time: time.hour)
calls['Months'] = calls['timeStamp'].apply(lambda time: time.month)
calls['Days'] = calls['timeStamp'].apply(lambda time: time.dayofweek)
type(calls['Days'].iloc[0])<jupyter_output><empty_output><jupyter_text>** Day of Week is an integer type so in order to display it on a plot I want to change it to a map with strings **<jupyter_code>days = {0:'Mon',1:'Tue',2:'Wed',3:'Thu',4:'Fri',5:'Sat',6:'Sun'}
calls['Days'] = calls['Days'].map(days)<jupyter_output><empty_output><jupyter_text>Plots With 911 Call Data<jupyter_code>sb.countplot(x='Days',data=calls,hue='Call Reason',palette='viridis')

plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)<jupyter_output><empty_output><jupyter_text>** This plot shows the number of calls for each type of emergency depending on the day of the week **<jupyter_code>sb.countplot(x='Months',data=calls,hue='Call Reason',palette='viridis')

plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)<jupyter_output><empty_output><jupyter_text>** This plot is missing months 9 through 11 so I am going to try another type of plot to display the data **<jupyter_code>byMonth = calls.groupby('Months').count()
byMonth.head()
byMonth['Call Reason'].plot()<jupyter_output><empty_output><jupyter_text>** This plot shows the number of calls each month regardless of the column it is set to **<jupyter_code>calls['Date']=calls['timeStamp'].apply(lambda t: t.date())<jupyter_output><empty_output><jupyter_text>** Created a Date column to display data on plots **<jupyter_code>calls.groupby('Date').count()['Call Reason'].plot()
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>** The following plots are divided up by the three emergency types and they display the number of calls for each one on a given date **<jupyter_code>calls[calls['Call Reason']=='Traffic'].groupby('Date').count()['Call Reason'].plot()
plt.title('Traffic')
plt.tight_layout()
calls[calls['Call Reason']=='Fire'].groupby('Date').count()['Call Reason'].plot()
plt.title('Fire')
plt.tight_layout()
calls[calls['Call Reason']=='EMS'].groupby('Date').count()['Call Reason'].plot()
plt.title('EMS')
plt.tight_layout()
dayHour = calls.groupby(by=['Days','Hours']).count()['Call Reason'].unstack()
dayHour.head()<jupyter_output><empty_output><jupyter_text>** Created a new dataframe that has the number of calls for each day of the week and each hour of the day and a heatmap showing this data **<jupyter_code>plt.figure(figsize=(10,6))
sb.heatmap(dayHour,cmap='Reds')
dayMonth = calls.groupby(by=['Days','Months']).count()['Call Reason'].unstack()
dayMonth.head()<jupyter_output><empty_output><jupyter_text>** I created another dataframe that has the count for each day of the month using a groupby then used that dataframe to create another heatmap **<jupyter_code>plt.figure(figsize=(10,6))
sb.heatmap(dayMonth,cmap='Reds')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14465408805031446, 'fraction_numerical': 0.009853249475890986, 'mean_word_length': 7.9344569288389515, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '601974', 'license': 'MIT', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1560, 'n_words': 445, 'path': '911 Calls.ipynb', 'repo_name': 'rsparks93/911-calls', 'size': '4776'}