<jupyter_start><jupyter_text>Adding new features Custom lambda expression to add new feature 'Reason' . *For example, if the title column value is EMS: BACK PAINS/INJURY , the Reason column value would be EMS. *<jupyter_code>x = df['title'].iloc[0]
x.split(':')[0]
df['Reason'] = df['title'].apply(lambda title: title.split(':')[0])
df['Reason']
#Most common reason

df['Reason'].value_counts()
#Seaborn to create countplot

sns.countplot(x='Reason', data=df)
sns.countplot(x='Reason', data=df, palette='viridis')
#Datatype of timestamp col

df.info()
type(df['timeStamp'].iloc[0])
#Converting them to datetime object
df['timeStamp'] = pd.to_datetime(df['timeStamp'])
type(df['timeStamp'].iloc[0])
 #Grab and call objects
    
time = df['timeStamp'].iloc[0]   
time.hour
time.year
time.hour
time.month
time.dayofweek
df['Hour'] = df['timeStamp'].apply(lambda time: time.hour)
df['Month'] = df['timeStamp'].apply(lambda time: time.month)
df['Day of Week'] = df['timeStamp'].apply(lambda time: time.dayofweek)

 df.head()<jupyter_output><empty_output><jupyter_text>** Notice how the Day of Week is an integer 0-6. Use the .map() with this dictionary to map the actual string names to the day of the week: **<jupyter_code>dmap = {0:'Mon',1:'Tue',2:'Wed',3:'Thu',4:'Fri',5:'Sat',6:'Sun'}
df['Day of Week'] = df['Day of Week'].map(dmap)
df.head()
sns.countplot( x='Day of Week', data=df)
sns.countplot( x='Day of Week', data=df, hue='Reason')
sns.countplot( x='Day of Week', data=df, hue='Reason', palette ='viridis')
sns.countplot(x='Month',data=df,hue='Reason',palette='viridis')

# To relocate the legend
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
# It is missing some months! 9,10, and 11 are not there.

byMonth = df.groupby('Month').count()
byMonth.head()
byMonth['twp'].plot()
sns.lmplot(x='Month',y='twp',data=byMonth.reset_index())<jupyter_output><empty_output><jupyter_text>**Create a new column called 'Date' that contains the date from the timeStamp column. You'll need to use apply along with the .date() method. **<jupyter_code>df['Date']=df['timeStamp'].apply(lambda t: t.date())
df.groupby('Date').count()['twp'].plot()
plt.tight_layout()
df[df['Reason']=='Traffic'].groupby('Date').count()['twp'].plot()
plt.title('Traffic')
plt.tight_layout()
df[df['Reason']=='Fire'].groupby('Date').count()['twp'].plot()
plt.title('Fire')
plt.tight_layout()
df[df['Reason']=='EMS'].groupby('Date').count()['twp'].plot()
plt.title('EMS')
plt.tight_layout()
#Creating heatmaps

dayHour = df.groupby(by=['Day of Week','Hour']).count()['Reason'].unstack()
dayHour.head()
plt.figure(figsize=(12,6))
sns.heatmap(dayHour,cmap='coolwarm')
sns.clustermap(dayHour,cmap='viridis')
dayMonth = df.groupby(by=['Day of Week','Month']).count()['Reason'].unstack()
dayMonth.head()
plt.figure(figsize=(12,6))
sns.heatmap(dayMonth,cmap='seismic')
sns.clustermap(dayMonth,cmap='viridis')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2052161976664379, 'fraction_numerical': 0.01098146877144818, 'mean_word_length': 7.498542274052478, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '24904', 'license': 'MIT', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1085, 'n_words': 226, 'path': 'Exploratory-Analysis-911-Calls/911_calls.ipynb', 'repo_name': 'void-02/Awesome-Machine-Learning-Models', 'size': '2914'}