This report analyzes a sample of 10,000 records from the Seattle Police Calls for Service dataset. The dataset includes information about the types of police calls recorded, dispatch priority codes, the dates and times calls were queued, and the police precincts associated with those records.
The purpose of this analysis is to better understand the patterns within the dataset. Specifically, I wanted to examine which types of calls appeared most frequently, how calls were distributed across priority codes, whether call activity varied by time and day of the week, and which dispatch precincts accounted for the largest shares of records.
Using Python, I created five visualizations to explore these questions. Each graph provides a different perspective on the data, allowing me to identify patterns and compare different aspects of police call activity. Because the analysis uses a sample of records rather than the complete dataset, the findings should be interpreted as patterns within the sample rather than conclusions about all police activity in Seattle.
The Seattle Police Calls dataset contains 10,000 records and 48 columns. These columns include information about the initial call type, dispatch priority, time of the call, number of officers, and dispatch precinct.
Before creating my visualizations, I examined the dataset to understand its structure, identify missing values, and determine which variables would be most useful for my analysis. Since some of the columns contain identification numbers or category codes, I focused primarily on frequency counts rather than interpreting numerical averages for those variables.
import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/ProgramData/Anaconda3/Library/plugins/platforms'
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
path = "U:/"
df = pd.read_csv(path + 'Seattle_Police_Calls.csv')
print(df.shape)
print("Dataset Dimensions:")
print(df.shape)
print("Column Information:")
df.info()
print("Missing Values:")
print(df.isna().sum())
print("Descriptive Statistics:")
print(df.describe())
print("Initial Police Call Types:")
print(df['initial_call_type'].value_counts())
print("Dispatch Priorities:")
print(df['priority'].value_counts())
print("Dispatch Precincts:")
print(df['dispatch_precinct'].value_counts())
The descriptive statistics show that the dataset includes 228 different initial police call types. This suggests that police calls for service cover a wide range of incidents and activities rather than one specific category.
Looking at dispatch priorities, codes 3 and 2 appear most frequently, with 2,823 and 2,807 records respectively. Priority 1 follows with 2,220 records. There are also three records without an assigned priority value.
An important limitation is that the dataset contains records from multiple years. Therefore, the results describe patterns within this particular sample of 10,000 records and should not automatically be generalized to all police calls in Seattle.
| Measure | Result |
|---|---|
| Total records | 10,000 |
| Total columns | 48 |
| Unique initial call types | 228 |
| Records with priority information | 9,997 |
| Missing priority values | 3 |
| Most represented precinct | West (2,952 records) |
| Second most represented precinct | North (2,616 records) |
For my first visualization, I created a horizontal bar chart showing the ten most frequently recorded initial police call types. I chose this graph because it makes it easier to compare different categories and identify which types of calls appear most often in the dataset.
df1 = df[['cad_event_number',
'initial_call_type',
'priority',
'cad_event_original_time_queued',
'dispatch_precinct']]
myresult = df1.groupby('initial_call_type', as_index=False)['cad_event_number'].count()
myresult.rename(columns={'cad_event_number': 'Number of Records'}, inplace=True)
d3 = myresult.sort_values('Number of Records', ascending=False).head(10)
d3 = d3.sort_values('Number of Records', ascending=True)
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(18, 12))
ax1 = fig.add_subplot(1, 1, 1)
ax1.barh(d3['initial_call_type'],
d3['Number of Records'],
color='lightcoral')
for row_counter, value_at_row_counter in enumerate(d3['Number of Records']):
ax1.text(value_at_row_counter+5, row_counter,
str(value_at_row_counter),
color='black', size=12, fontweight='bold',
ha='left', va='center',
backgroundcolor='white')
plt.xlim(0, d3['Number of Records'].max()*1.1)
plt.axvline(d3['Number of Records'].mean(),
color='black', linestyle='dashed')
ax1.text(d3['Number of Records'].mean()+5, 0,
'Top 10 Mean = ' + str(round(d3['Number of Records'].mean(), 1)),
rotation=0, fontsize=12,
backgroundcolor='white')
ax1.set_title('Top 10 Initial Police Call Types in Seattle', size=20)
ax1.set_xlabel('Number of Records', fontsize=16)
ax1.set_ylabel('Initial Police Call Type', fontsize=16)
plt.tight_layout()
plt.show()
Looking at the horizontal bar chart, I noticed that suspicious person,
vehicle, or incident calls appeared most frequently in my dataset, with
632 records. Disturbances followed closely with 613 records, while
premise checks accounted for 511 records. These three categories had
higher counts than the other call types in the top ten.
What stood out to me was the variety of calls represented in the chart. Not all of the records involve the same kind of situation, and some categories include officer-initiated activities. The dashed line represents the average number of records across the ten categories shown, making it easier to compare which call types appeared above or below that average.
Overall, this graph helped me understand which initial call types were most common in my sample. However, since the dataset contains only 10,000 selected records, these results do not necessarily represent the most common police calls across Seattle as a whole.
For my second visualization, I created a vertical bar chart to examine how police call records are distributed across different dispatch priority codes. I chose this graph because it allows me to compare the frequency of each priority code and identify which ones appear most often in my dataset.
d4 = df1.groupby('priority', as_index=False)['cad_event_number'].count()
d4.rename(columns={'cad_event_number': 'Number of Records'}, inplace=True)
d4 = d4.sort_values('priority', ascending=True)
fig = plt.figure(figsize=(14, 9))
ax1 = fig.add_subplot(1, 1, 1)
ax1.bar(d4['priority'], d4['Number of Records'], color='steelblue')
for row_counter, value_at_row_counter in enumerate(d4['Number of Records']):
ax1.text(d4['priority'][row_counter],
value_at_row_counter+40,
str(value_at_row_counter),
color='black', size=12, fontweight='bold',
ha='center', va='bottom')
plt.ylim(0, d4['Number of Records'].max()*1.15)
ax1.set_title('Distribution of Seattle Police Dispatch Priority Codes\n(10,000-Record Sample)', size=20)
ax1.set_xlabel('Dispatch Priority Code', fontsize=16)
ax1.set_ylabel('Number of Police Call Records', fontsize=16)
plt.xticks(d4['priority'], fontsize=14)
plt.yticks(fontsize=14)
plt.show()
Looking at the vertical bar chart, I noticed that priority codes 3 and 2
appeared most frequently in my dataset, with 2,823 and 2,807 records.
Priority code 1 followed with 2,220 records. These three codes had
noticeably higher counts than most of the other categories, showing that
the records in my sample were not evenly distributed across priority
codes.
What stood out to me was the difference between the most and least frequent codes. For example, priority code 6 had only 32 records, while priority code 7 had 1,399. I also noticed that codes 4, 5, and 9 had relatively low counts compared to codes 1, 2, and 3. The vertical bar chart made these differences easier to recognize and compare.
Overall, this graph helped me understand how dispatch priority codes were distributed throughout the dataset. Three records were missing priority information, so the chart represents 9,997 records rather than the full 10,000. Since the codes are numerical categories, I focused on their frequencies rather than assuming what each code means in terms of urgency.
For my third visualization, I created a multiple-line plot to examine how the number of police call records changes throughout the day and across different weekdays. I wanted to see whether certain hours had higher call counts and whether the patterns were similar or different depending on the day of the week.
I chose a line graph because it makes it easier to compare changes over time, especially when looking at multiple days on the same chart.
df2 = df1.copy()
df2['cad_event_original_time_queued'] = pd.to_datetime(
df2['cad_event_original_time_queued'], errors='coerce')
df2['hour'] = df2['cad_event_original_time_queued'].dt.hour
df2['weekday'] = df2['cad_event_original_time_queued'].dt.strftime('%a')
line_df = df2.groupby(['hour', 'weekday'])['cad_event_number'].count().reset_index(name='Number of Records')
my_colors = {'Mon':'blue',
'Tue':'red',
'Wed':'green',
'Thu':'gray',
'Fri':'purple',
'Sat':'gold',
'Sun':'brown'}
fig = plt.figure(figsize=(18, 10))
ax = fig.add_subplot(1, 1, 1)
for key, grp in line_df.groupby('weekday'):
grp.plot(ax=ax, kind='line', x='hour',
y='Number of Records',
color=my_colors[key], label=key, marker='8')
plt.title('Seattle Police Calls by Hour and Day of Week\n(10,000-Record Sample)', fontsize=18)
ax.set_xlabel('Hour (24 Hour Interval)', fontsize=18)
ax.set_ylabel('Number of Police Call Records', fontsize=18, labelpad=20)
ax.tick_params(axis='x', labelsize=14, rotation=0)
ax.tick_params(axis='y', labelsize=14, rotation=0)
ax.set_xticks(np.arange(24))
handles, labels = ax.get_legend_handles_labels()
handles = [handles[1], handles[5], handles[6],
handles[4], handles[0], handles[2], handles[3]]
labels = [labels[1], labels[5], labels[6],
labels[4], labels[0], labels[2], labels[3]]
plt.legend(handles, labels, loc='best', fontsize=14, ncol=1)
plt.show()
Looking at the multiple-line graph, I noticed that the number of police
call records changes depending on the hour and day of the week. Overall,
the early morning hours tend to have fewer records, while several of the
lines increase during the afternoon and evening. This shows that call
activity is not distributed evenly throughout the day in my sample.
What stood out to me was that the seven weekdays do not follow exactly the same pattern. Although some days show similar increases and decreases, there are also differences in the number of records at certain hours. Having all seven days on the same graph made it easier for me to compare these patterns instead of examining each day separately.
Overall, this visualization helped me better understand the relationship between the time of day, day of the week, and the number of police call records. Since the dataset includes records from multiple years, these results only describe the distribution within my sample and do not necessarily represent a typical day or week for Seattle police.
For my fourth visualization, I created a donut chart to examine how police call records were distributed across Seattle’s dispatch precincts. I wanted to see which precincts accounted for the largest portions of my dataset and whether some precincts had noticeably more records than others.
I chose a donut chart because it allows me to compare each precinct’s percentage of the total while also showing the overall number of records in the center.
donut_df = df1.groupby('dispatch_precinct', as_index=False)['cad_event_number'].count()
donut_df.rename(columns={'cad_event_number': 'Number of Records'}, inplace=True)
donut_df = donut_df.sort_values('Number of Records', ascending=False)
donut_df.reset_index(inplace=True, drop=True)
number_outside_colors = len(donut_df['dispatch_precinct'].unique())
outside_color_ref_number = np.arange(number_outside_colors) * (20 // number_outside_colors)
fig = plt.figure(figsize=(12, 12))
ax = fig.add_subplot(1, 1, 1)
color_map = plt.get_cmap('tab20c')
outer_colors = color_map(outside_color_ref_number)
all_calls = donut_df['Number of Records'].sum()
donut_df.groupby('dispatch_precinct')['Number of Records'].sum().plot(
ax=ax,
kind='pie',
radius=1,
colors=outer_colors,
pctdistance=0.78,
labeldistance=1.1,
wedgeprops={'edgecolor':'white'},
textprops={'fontsize':12},
autopct=lambda p: '{:.1f}%'.format(p),
startangle=90
)
hole = plt.Circle((0, 0), 0.3, fc='white')
fig1 = plt.gcf()
fig1.gca().add_artist(hole)
ax.yaxis.set_visible(False)
plt.title('Seattle Police Call Records by Dispatch Precinct\n(10,000-Record Sample)', fontsize=18)
ax.axis('equal')
ax.text(0, 0, 'Records\n' + str(all_calls),
ha='center', va='center', size=13)
plt.tight_layout()
plt.show()
Looking at the donut chart, I noticed that the West precinct accounted
for the largest percentage of police call records in my dataset, at
29.5%. North followed with 26.2%, while South and East each accounted
for approximately 16.2%. Southwest represented 11.3%, and only 0.6% of
records were classified as Unknown.
What stood out to me was that West and North together accounted for more than half of the 10,000 records. I also noticed that South and East had almost identical percentages, even though their record counts were slightly different. The donut chart made it easier to see how each precinct contributed to the overall sample.
Overall, this visualization helped me understand how the records were distributed across the different dispatch precincts. However, having a larger percentage of records does not necessarily mean that a precinct has more crime. Differences in population, geography, and police activity may affect these numbers. Therefore, the chart should be interpreted as a comparison of records within my dataset rather than a measure of crime across Seattle.
For my fifth visualization, I created a heatmap to compare dispatch priority codes across Seattle’s different precincts. I wanted to see whether certain priority codes appeared more frequently in some precincts than others.
I chose a heatmap because the colors make it easier to identify differences in record counts across two categories at the same time. Rather than examining priority codes and precincts separately, this visualization allows me to compare them together.
d7 = df1.groupby(['dispatch_precinct', 'priority'], as_index=False)['cad_event_number'].count()
d7.rename(columns={'cad_event_number': 'Number of Records'}, inplace=True)
hm_df = pd.pivot(d7,
index='dispatch_precinct',
columns='priority',
values='Number of Records')
hm_df
import seaborn as sns
fig = plt.figure(figsize=(18, 10))
ax = fig.add_subplot(1, 1, 1)
ax = sns.heatmap(hm_df,
linewidths=0.2,
annot=True,
cmap='coolwarm',
fmt=',.0f',
square=False,
annot_kws={'size':11},
cbar_kws={'orientation':'vertical'})
plt.title('Seattle Police Call Records by Precinct and Priority',
fontsize=18, pad=15)
plt.xlabel('Dispatch Priority Code', fontsize=16, labelpad=10)
plt.ylabel('Dispatch Precinct', fontsize=16, labelpad=10)
plt.xticks(fontsize=14)
plt.yticks(rotation=0, fontsize=14)
cbar = ax.collections[0].colorbar
cbar.set_label('Number of Records',
rotation=270, fontsize=14, labelpad=20)
plt.show()
Looking at the heatmap, I noticed that the number of police call records
varied depending on both the dispatch precinct and priority code. West
and North had some of the highest counts in several priority categories,
particularly codes 2 and 3. The colors helped me identify these
differences without having to compare every number individually.
What stood out to me was that the priority codes were not distributed equally across precincts. Some combinations had noticeably higher counts, while others had relatively few records. I also noticed that the Unknown category had much lower counts than the named precincts.
Overall, this heatmap helped me compare two variables at the same time and understand how the distribution of priority codes differed across precincts in my sample. However, these numbers do not necessarily indicate differences in crime levels or the seriousness of incidents. The heatmap shows record counts rather than rates, and the data does not account for differences in precinct population or activity.
Overall, analyzing the Seattle Police Calls dataset helped me better understand how police call records differ based on call type, priority code, time, and dispatch precinct. Through my five visualizations, I was able to identify several patterns that were not as obvious when looking at the raw data.
One of the biggest things I noticed was that certain call types, such as suspicious persons and disturbances, appeared more frequently than others. Priority codes 2 and 3 were also among the most common, while the multiple-line graph showed differences in record counts throughout the day and across weekdays. When comparing precincts, West and North accounted for more than half of the records in my sample. The heatmap helped me take this analysis further by showing how priority codes were distributed across different precincts.
Something important I learned from this project is that the way data is visualized can make a difference in how easily patterns can be identified. Each graph allowed me to examine the dataset from a different perspective, whether I was comparing categories, looking at changes over time, or examining relationships between variables.
However, there are limitations to my analysis. The dataset contains a sample of 10,000 records from multiple years, so the results should not be interpreted as representing all police activity in Seattle. Also, the number of police call records does not necessarily reflect crime levels, since some records involve other types of police activity. Despite these limitations, the visualizations provided a useful overview of the patterns within my dataset.
import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/ProgramData/Anaconda3/Library/plugins/platforms'
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
path = "U:/"
df = pd.read_csv(path + 'Seattle_Police_Calls.csv')
print(df.shape)
print("Dataset Dimensions:")
print(df.shape)
print("Column Information:")
df.info()
print("Missing Values:")
print(df.isna().sum())
print("Descriptive Statistics:")
print(df.describe())
print("Initial Police Call Types:")
print(df['initial_call_type'].value_counts())
print("Dispatch Priorities:")
print(df['priority'].value_counts())
print("Dispatch Precincts:")
print(df['dispatch_precinct'].value_counts())
print("Dataset Dimensions:")
print(df.shape)
print("Column Information:")
df.info()
print("Missing Values:")
print(df.isna().sum())
print("Descriptive Statistics:")
print(df.describe())
print("Initial Police Call Types:")
print(df['initial_call_type'].value_counts())
print("Dispatch Priorities:")
print(df['priority'].value_counts())
print("Dispatch Precincts:")
print(df['dispatch_precinct'].value_counts())
print("Dataset Dimensions:")
print(df.shape)
print("Column Information:")
df.info()
print("Missing Values:")
print(df.isna().sum())
print("Descriptive Statistics:")
print(df.describe())
print("Initial Police Call Types:")
print(df['initial_call_type'].value_counts())
print("Dispatch Priorities:")
print(df['priority'].value_counts())
print("Dispatch Precincts:")
print(df['dispatch_precinct'].value_counts())
The descriptive statistics show that the dataset includes 228 different initial police call types. This suggests that police calls for service cover a wide range of incidents and activities rather than one specific category.
Looking at dispatch priorities, codes 3 and 2 appear most frequently, with 2,823 and 2,807 records respectively. Priority 1 follows with 2,220 records. There are also three records without an assigned priority value.
An important limitation is that the dataset contains records from multiple years. Therefore, the results describe patterns within this particular sample of 10,000 records and should not automatically be generalized to all police calls in Seattle.