Mass Shootings

Jupyter Notebook CSS

div .dataframe { border:none; margin: 0 auto; } div.output_stdout pre { max-height:300px; } div.output_stderr pre { background: #fdd; margin:0; max-height:300px; } div.hl-ipython3 pre { margin:0 } .dataframe thead tr:only-child th { text-align: right; text-transform: capitalize; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; } .rendered_html tbody tr:nth-child(odd), .rendered_html tbody tr:nth-child(odd) td { background: #f5f5f5; } .rendered_html tr, .rendered_html th, .rendered_html td { text-align: right; vertical-align: middle; padding: 0.5em 0.5em; line-height: normal; white-space: normal; max-width: none; border: none; } div.highlight .kn, .n, .k, .nn, .s1, .ow, .p, .mi, .c, .mf, .nb, .kc, .sd, .nf { font-family: monospace; font-size:14px; } .input_prompt { color: #303F9F; font-weight: bold; float: left; margin-right: 5px; margin-top: 3px; } .input_area pre { border: 1px solid #cfcfcf; border-radius: 2px; background: #f7f7f7; line-height: 1.21429em; padding: 6px 3px 6px 6px; } .output_prompt{ color:#cc0000; font-weight: bold; } .prompt{ font-family: monospace; font-size: 14px; } .c, c1 { color: #408080; font-style: italic; } .k { color: #338822; font-weight: bold; } .kn { color: #338822; font-weight: bold; } .mi { color: #008800; } .mf { color: #008800; } .o { color: #9966ff; } .ow { color: #BA22FF; font-weight: bold; } .nb { color: #338822; } .n { color: #000000; } .s, .s1, .sd, .s2 { color: #cc2222; } .se { color: #cc2222; font-weight: bold; } .si { color: #C06688; font-weight: bold; } .nn { color: #4D00FF; font-weight: bold; } .output_area pre { background-color: #FFFFFF; padding-left: 5%; } .code_cell { padding-left: 1%; } .cell { margin-top: 10px; margin-bottom: 10px; } br { line-height: 2; } blockquote { font-size: 1em; text-align: left; font-weight: normal; } code { border: none; box-shadow: none; font-family: monospace; } div.rendered_html h1, h2, h3, h4 { margin-top: 30px; margin-bottom: 10px; } div.rendered_html p a { color: #4D00FF; }

Mass Shootings

In [801]:
import pandas as pd
import numpy as np
import datetime
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import seaborn as sns
from sklearn import linear_model

%matplotlib inline
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('max_colwidth',-1)

The purpose of this project is to explore the US Mass Shootings Data from Kaggle to answer below questions:

• How many people got killed and injured per year?

• Visualize mass shootings on the U.S map

• Is there any correlation between shooter and his/her race, gender

• Any correlation with calendar dates? Do we have more deadly days, weeks or months on average

• What cities and states are more prone to such attacks

• Can you find and combine any other external datasets to enrich the analysis, for example, gun ownership by state

• Any other pattern you see that can help in prediction, crowd safety or in-depth analysis of the event

• How many shooters have some kind of mental health problem? Can we compare that shooter with general population with same condition.

In [802]:
df = pd.read_csv('Mass Shootings Dataset Ver 5.csv', encoding = "ISO-8859-1", parse_dates=["Date"])
In [803]:
df.head()
Out[803]:
S# Title Location Date Incident Area Open/Close Location Target Cause Summary Fatalities Injured Total victims Policeman Killed Age Employeed (Y/N) Employed at Mental Health Issues Race Gender Latitude Longitude
0 1 Texas church mass shooting Sutherland Springs, TX 2017-11-05 Church Close random unknown Devin Patrick Kelley, 26, an ex-air force officer, shot and killed 26 people and wounded 20 at a church in Texas. He was found dead later in his vehicle. 26 20 46 0.0 26 NaN NaN No White M NaN NaN
1 2 Walmart shooting in suburban Denver Thornton, CO 2017-11-01 Wal-Mart Open random unknown Scott Allen Ostrem, 47, walked into a Walmart in a suburb north of Denver and fatally shot two men and a woman, then left the store and drove away. After an all-night manhunt, Ostrem, who had financial problems but no serious criminal history, was captured by police after being spotted near his apartment in Denver. 3 0 3 0.0 47 NaN NaN No White M NaN NaN
2 3 Edgewood businees park shooting Edgewood, MD 2017-10-18 Remodeling Store Close coworkers unknown Radee Labeeb Prince, 37, fatally shot three people and wounded two others around 9am at Advance Granite Solutions, a home remodeling business where he worked near Baltimore. Hours later he shot and wounded a sixth person at a car dealership in Wilmington, Delaware. He was apprehended that evening following a manhunt by authorities. 3 3 6 0.0 37 NaN Advance Granite Store No Black M NaN NaN
3 4 Las Vegas Strip mass shooting Las Vegas, NV 2017-10-01 Las Vegas Strip Concert outside Mandala Bay Open random unknown Stephen Craig Paddock, opened fire from the 32nd floor of Manadalay Bay hotel at Last Vegas concert goers for no obvious reason. He shot himself and died on arrival of law enforcement agents. He was 64 59 527 585 1.0 64 NaN NaN Unclear White M 36.181271 -115.134132
4 5 San Francisco UPS shooting San Francisco, CA 2017-06-14 UPS facility Close coworkers NaN Jimmy Lam, 38, fatally shot three coworkers and wounded two others inside a UPS facility in San Francisco. Lam killed himself as law enforcement officers responded to the scene. 3 2 5 0.0 38 1.0 NaN Yes Asian M NaN NaN
In [804]:
df = df.sort_values('Date')
df.head()
Out[804]:
S# Title Location Date Incident Area Open/Close Location Target Cause Summary Fatalities Injured Total victims Policeman Killed Age Employeed (Y/N) Employed at Mental Health Issues Race Gender Latitude Longitude
322 323 University of Texas at Austin Austin, Texas 1966-08-01 University of Texas Close random terrorism On August 1, 1966, a 25-year-old engineering student at the University of Texas in Austin killed sixteen people and wounded thirty-two others in and around the Tower of the University of Texas. Prior to commencing the mass shootings at the University, the student and former U.S. Marine, had murdered both his wife and mother in Austin, Texas. 17 32 48 0.0 25 NaN NaN Yes White American or European American Male 30.198887 -97.844159
321 322 Rose-Mar College of Beauty Mesa, Arizona 1966-11-12 Rose-Mar College of Beauty Close random terrorism On November 12, 1966, an 18-year-old high school student entered the Rose-Mar College of Beauty in Mesa, Arizona, ordering his victims to lay on the ground in a circle. The gunman shot and killed four women and a child and injured another woman and an infant. He considered a few sites, like his school, where he thought of wiping out the teachers. Finally, he settled on the Rose-Mar College of Beauty, where he thought he'd get a nice large group of victims. 5 1 6 0.0 18 NaN NaN Yes White American or European American Male 33.422687 -111.816320
320 321 St. Aloysius Church Spokane, Washington 1971-11-11 Church Close random terrorism On November 11, 1971, a former MIT student entered St. Aloysius Roman Catholic Church on the Gonzaga University campus. The shooter killed the caretaker and wounded four more people before he was killed by police. 2 4 5 0.0 NaN NaN NaN Yes White American or European American Male 47.673674 -117.415984
319 320 New Orleans Police Shootings New Orleans, Louisiana 1972-12-31 NaN NaN random psycho On New Year's Eve in 1972, a 23-year-old ex-Navy dental technician went to the central lockup New Orleans Police Department and shot four policeman that day. Seven days later on January 7, 1973, the shooter shot a grocer and entered the Downtown Howard Johnson Hotel where he shot seventeen people before killed him at the top of the hotel roof. 10 13 22 4.0 23 NaN NaN Yes Black American or African American Male 30.068724 -89.931474
318 319 Clara Barton Elementary School Chicago, Illinois 1974-01-17 Clara Barton Elementary School Close Teachers anger On January 17, 1974, a 14-year-old student entered Clara Barton Elementary School in Chicago, Illinois and killed the principal and wounded three others before he was seized by a teacher when both his guns jammed. Apparently, the student was angry at the fact that he had been expelled from the school and transferred to a social adjustment center earlier that week. 1 3 4 0.0 14 NaN NaN Yes Unknown Male 41.839280 -87.688181
In [805]:
df.isnull().sum()
Out[805]:
S#                      0  
Title                   0  
Location                45 
Date                    0  
Incident Area           62 
Open/Close Location     28 
Target                  5  
Cause                   77 
Summary                 0  
Fatalities              0  
Injured                 0  
Total victims           0  
Policeman Killed        6  
Age                     144
Employeed (Y/N)         256
Employed at             282
Mental Health Issues    0  
Race                    2  
Gender                  0  
Latitude                20 
Longitude               20 
dtype: int64
In [806]:
df.shape
Out[806]:
(323, 21)

Create a US population DataFrame by year

In [807]:
population_dict = {'date': {pd.Timestamp('1966-01-01'): pd.Timestamp('1966-01-01'),
  pd.Timestamp('1967-01-01'): pd.Timestamp('1967-01-01'),
  pd.Timestamp('1968-01-01'): pd.Timestamp('1968-01-01'),
  pd.Timestamp('1969-01-01'): pd.Timestamp('1969-01-01'),
  pd.Timestamp('1970-01-01'): pd.Timestamp('1970-01-01'),
  pd.Timestamp('1971-01-01'): pd.Timestamp('1971-01-01'),
  pd.Timestamp('1972-01-01'): pd.Timestamp('1972-01-01'),
  pd.Timestamp('1973-01-01'): pd.Timestamp('1973-01-01'),
  pd.Timestamp('1974-01-01'): pd.Timestamp('1974-01-01'),
  pd.Timestamp('1975-01-01'): pd.Timestamp('1975-01-01'),
  pd.Timestamp('1976-01-01'): pd.Timestamp('1976-01-01'),
  pd.Timestamp('1977-01-01'): pd.Timestamp('1977-01-01'),
  pd.Timestamp('1978-01-01'): pd.Timestamp('1978-01-01'),
  pd.Timestamp('1979-01-01'): pd.Timestamp('1979-01-01'),
  pd.Timestamp('1980-01-01'): pd.Timestamp('1980-01-01'),
  pd.Timestamp('1981-01-01'): pd.Timestamp('1981-01-01'),
  pd.Timestamp('1982-01-01'): pd.Timestamp('1982-01-01'),
  pd.Timestamp('1983-01-01'): pd.Timestamp('1983-01-01'),
  pd.Timestamp('1984-01-01'): pd.Timestamp('1984-01-01'),
  pd.Timestamp('1985-01-01'): pd.Timestamp('1985-01-01'),
  pd.Timestamp('1986-01-01'): pd.Timestamp('1986-01-01'),
  pd.Timestamp('1987-01-01'): pd.Timestamp('1987-01-01'),
  pd.Timestamp('1988-01-01'): pd.Timestamp('1988-01-01'),
  pd.Timestamp('1989-01-01'): pd.Timestamp('1989-01-01'),
  pd.Timestamp('1990-01-01'): pd.Timestamp('1990-01-01'),
  pd.Timestamp('1991-01-01'): pd.Timestamp('1991-01-01'),
  pd.Timestamp('1992-01-01'): pd.Timestamp('1992-01-01'),
  pd.Timestamp('1993-01-01'): pd.Timestamp('1993-01-01'),
  pd.Timestamp('1994-01-01'): pd.Timestamp('1994-01-01'),
  pd.Timestamp('1995-01-01'): pd.Timestamp('1995-01-01'),
  pd.Timestamp('1996-01-01'): pd.Timestamp('1996-01-01'),
  pd.Timestamp('1997-01-01'): pd.Timestamp('1997-01-01'),
  pd.Timestamp('1998-01-01'): pd.Timestamp('1998-01-01'),
  pd.Timestamp('1999-01-01'): pd.Timestamp('1999-01-01'),
  pd.Timestamp('2000-01-01'): pd.Timestamp('2000-01-01'),
  pd.Timestamp('2001-01-01'): pd.Timestamp('2001-01-01'),
  pd.Timestamp('2002-01-01'): pd.Timestamp('2002-01-01'),
  pd.Timestamp('2003-01-01'): pd.Timestamp('2003-01-01'),
  pd.Timestamp('2004-01-01'): pd.Timestamp('2004-01-01'),
  pd.Timestamp('2005-01-01'): pd.Timestamp('2005-01-01'),
  pd.Timestamp('2006-01-01'): pd.Timestamp('2006-01-01'),
  pd.Timestamp('2007-01-01'): pd.Timestamp('2007-01-01'),
  pd.Timestamp('2008-01-01'): pd.Timestamp('2008-01-01'),
  pd.Timestamp('2009-01-01'): pd.Timestamp('2009-01-01'),
  pd.Timestamp('2010-01-01'): pd.Timestamp('2010-01-01'),
  pd.Timestamp('2011-01-01'): pd.Timestamp('2011-01-01'),
  pd.Timestamp('2012-01-01'): pd.Timestamp('2012-01-01'),
  pd.Timestamp('2013-01-01'): pd.Timestamp('2013-01-01'),
  pd.Timestamp('2014-01-01'): pd.Timestamp('2014-01-01'),
  pd.Timestamp('2015-01-01'): pd.Timestamp('2015-01-01'),
  pd.Timestamp('2016-01-01'): pd.Timestamp('2016-01-01'),
  pd.Timestamp('2017-01-01'): pd.Timestamp('2017-01-01')},
 'population': {pd.Timestamp('1966-01-01 00:00:00'): 196.56,
  pd.Timestamp('1967-01-01'): 198.7,
  pd.Timestamp('1968-01-01'): 200.7,
  pd.Timestamp('1969-01-01'): 202.6,
  pd.Timestamp('1970-01-01'): 205.0,
  pd.Timestamp('1971-01-01'): 207.66,
  pd.Timestamp('1972-01-01'): 209.9,
  pd.Timestamp('1973-01-01'): 211.9,
  pd.Timestamp('1974-01-01'): 213.8,
  pd.Timestamp('1975-01-01'): 215.9,
  pd.Timestamp('1976-01-01'): 218.0,
  pd.Timestamp('1977-01-01'): 220.2,
  pd.Timestamp('1978-01-01'): 222.5,
  pd.Timestamp('1979-01-01'): 225.0,
  pd.Timestamp('1980-01-01'): 227.2,
  pd.Timestamp('1981-01-01'): 229.4,
  pd.Timestamp('1982-01-01'): 231.6,
  pd.Timestamp('1983-01-01'): 233.7,
  pd.Timestamp('1984-01-01'): 235.8,
  pd.Timestamp('1985-01-01'): 237.9,
  pd.Timestamp('1986-01-01'): 240.1,
  pd.Timestamp('1987-01-01'): 242.2,
  pd.Timestamp('1988-01-01'): 244.5,
  pd.Timestamp('1989-01-01'): 246.8,
  pd.Timestamp('1990-01-01'): 249.6,
  pd.Timestamp('1991-01-01'): 252.9,
  pd.Timestamp('1992-01-01'): 256.5,
  pd.Timestamp('1993-01-01'): 259.9,
  pd.Timestamp('1994-01-01'): 263.1,
  pd.Timestamp('1995-01-01'): 266.2,
  pd.Timestamp('1996-01-01'): 269.3,
  pd.Timestamp('1997-01-01'): 272.6,
  pd.Timestamp('1998-01-01'): 275.8,
  pd.Timestamp('1999-01-01'): 279.0,
  pd.Timestamp('2000-01-01'): 282.1,
  pd.Timestamp('2001-01-01'): 284.9,
  pd.Timestamp('2002-01-01'): 287.6,
  pd.Timestamp('2003-01-01'): 290.1,
  pd.Timestamp('2004-01-01'): 292.8,
  pd.Timestamp('2005-01-01'): 295.5,
  pd.Timestamp('2006-01-01'): 298.3,
  pd.Timestamp('2007-01-01'): 301.2,
  pd.Timestamp('2008-01-01'): 304.0,
  pd.Timestamp('2009-01-01'): 306.7,
  pd.Timestamp('2010-01-01'): 309.3,
  pd.Timestamp('2011-01-01'): 311.6,
  pd.Timestamp('2012-01-01'): 314.0,
  pd.Timestamp('2013-01-01'): 316.1,
  pd.Timestamp('2014-01-01'): 318.5,
  pd.Timestamp('2015-01-01'): 320.8,
  pd.Timestamp('2016-01-01'): 323.1,
  pd.Timestamp('2017-01-01'): 325.3}}
df_popu = pd.DataFrame(population_dict)
df_popu.columns = ['date','population']
# set df_population.date to datetime format
df_popu.date = pd.to_datetime(df_popu.date)
# set dataframe index to Date colume
df_popu.index = df_popu.date
In [808]:
df_popu.head()
Out[808]:
date population
date
1966-01-01 1966-01-01 196.56
1967-01-01 1967-01-01 198.70
1968-01-01 1968-01-01 200.70
1969-01-01 1969-01-01 202.60
1970-01-01 1970-01-01 205.00
In [809]:
# Convert df.Date to Datetime format

df.Date = pd.to_datetime(df.Date)
In [810]:
# set df index to Date column
df.index = df.Date
In [811]:
df.head(2)
Out[811]:
S# Title Location Date Incident Area Open/Close Location Target Cause Summary Fatalities Injured Total victims Policeman Killed Age Employeed (Y/N) Employed at Mental Health Issues Race Gender Latitude Longitude
Date
1966-08-01 323 University of Texas at Austin Austin, Texas 1966-08-01 University of Texas Close random terrorism On August 1, 1966, a 25-year-old engineering student at the University of Texas in Austin killed sixteen people and wounded thirty-two others in and around the Tower of the University of Texas. Prior to commencing the mass shootings at the University, the student and former U.S. Marine, had murdered both his wife and mother in Austin, Texas. 17 32 48 0.0 25 NaN NaN Yes White American or European American Male 30.198887 -97.844159
1966-11-12 322 Rose-Mar College of Beauty Mesa, Arizona 1966-11-12 Rose-Mar College of Beauty Close random terrorism On November 12, 1966, an 18-year-old high school student entered the Rose-Mar College of Beauty in Mesa, Arizona, ordering his victims to lay on the ground in a circle. The gunman shot and killed four women and a child and injured another woman and an infant. He considered a few sites, like his school, where he thought of wiping out the teachers. Finally, he settled on the Rose-Mar College of Beauty, where he thought he'd get a nice large group of victims. 5 1 6 0.0 18 NaN NaN Yes White American or European American Male 33.422687 -111.816320
In [812]:
df.isnull().sum()
Out[812]:
S#                      0  
Title                   0  
Location                45 
Date                    0  
Incident Area           62 
Open/Close Location     28 
Target                  5  
Cause                   77 
Summary                 0  
Fatalities              0  
Injured                 0  
Total victims           0  
Policeman Killed        6  
Age                     144
Employeed (Y/N)         256
Employed at             282
Mental Health Issues    0  
Race                    2  
Gender                  0  
Latitude                20 
Longitude               20 
dtype: int64
In [813]:
df_population.isnull().sum()
Out[813]:
date          0
population    0
dtype: int64

How many shooting per year?

Let's analyse the number of attack each year (1966 - 2017)

In [814]:
df['Year'] = df['Date'].dt.year

cnt_srs = df['Year'].value_counts()
plt.figure(figsize=(12,6))
sns.barplot(cnt_srs.index, cnt_srs.values, alpha=0.8, color='purple')
plt.xticks(rotation='vertical')
plt.xlabel('Year', fontsize=15)
plt.ylabel('Number of Shootings', fontsize=15)
plt.title('Number of Shootings per Year', fontsize=18)
plt.show()

Let's check the number of attacks every 5 years

In [815]:
date = pd.date_range(start='1966-01-01', end='2017-01-01', freq='AS')

# AS indicate year start frequency
# http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases
In [816]:
fig,ax = plt.subplots(figsize= (15,8))
ax.plot(date,df.Fatalities.resample('AS').count(),'-o')
# set xaxis major labels
ax.xaxis.set_major_locator(mdates.YearLocator(5,month=1,day=1)) # Every 3 years
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# set grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Total Number of Attacks');
plt.title('Total Number of Attacks per Year')
Out[816]:
<matplotlib.text.Text at 0x1442a5b90>

As we can see, there has been a gradual increased in attacks since 2010 and a massive increase in 2016 then a big drop in 2017.

Is there a possibility that the gradual increase is due to increase in population per year? Well, let check attacks per Million people each year.

Attacks per Million people each year.

Numbers of attack every 5 years per Million people

In [817]:
pop_num = df_popu.population #Population column from df_popu
count = df.Fatalities.resample('AS').count() # Total numbers of fatalities
fatal_count = count / pop_num # Number of attacks per population
fig,ax = plt.subplots(figsize=(15,8))
ax.plot(date,fatal_count,'-o', color = 'g')
# major labels
ax.xaxis.set_major_locator(mdates.YearLocator(5,month=1,day=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Total Number of Attacks per Million people')
plt.title('Total Number of Attacks per Year')
Out[817]:
<matplotlib.text.Text at 0x143dfca10>

There seems to be consistency between the number of attack each year graph and the number of attacks per Million people each year graph.

How many people got killed and injured per year?

Number of People that got killed per year

In [818]:
fig,ax = plt.subplots(figsize= (18,8))
ax.plot(date,df.Fatalities.resample('AS').sum().fillna(0),'-o')
# set xaxis major labels
ax.xaxis.set_major_locator(mdates.YearLocator(3,month=1,day=1)) # Every 3 years
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# set grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Number of Death');
plt.title('Number of Death per Year')
Out[818]:
<matplotlib.text.Text at 0x144622590>

Number of People that got injured per year

In [819]:
fig,ax = plt.subplots(figsize= (18,8))
ax.plot(date,df.Injured.resample('AS').sum().fillna(0),'-o')
# set xaxis major labels
ax.xaxis.set_major_locator(mdates.YearLocator(3,month=1,day=1)) # Every 3 years
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# set grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Number of Injured');
plt.title('Number of Injured per Year')
Out[819]:
<matplotlib.text.Text at 0x14490c590>

Total number of victims per year

In [820]:
fig,ax = plt.subplots(figsize= (18,8))
ax.plot(date,df['Total victims'].resample('AS').sum().fillna(0),'-o')
# set xaxis major labels
ax.xaxis.set_major_locator(mdates.YearLocator(3,month=1,day=1)) # Every 3 years
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# set grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Number of Total victims');
plt.title('Number of Total victims per Year')
Out[820]:
<matplotlib.text.Text at 0x1449fad50>

Total number of Policeman Killed per year

In [821]:
fig,ax = plt.subplots(figsize= (18,8))
ax.plot(date,df['Policeman Killed'].resample('AS').sum().fillna(0),'-o')
# set xaxis major labels
ax.xaxis.set_major_locator(mdates.YearLocator(3,month=1,day=1)) # Every 3 years
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# set grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Number of Policeman Killed');
plt.title('Number of Policeman Killed per Year')
Out[821]:
<matplotlib.text.Text at 0x144cfc350>

How many shooting (Million Population) per year?

In [822]:
pop_num = df_popu.population #Population column from df_popu
fatal_sum = df.Fatalities.resample('AS').sum() # Total numbers of fatalities
fatal_pop = fatal_sum / pop_num # Number of attacks per population
fig,ax = plt.subplots(figsize=(18,8))
ax.plot(date,fatal_count,'-o', color = 'g')
# major labels
ax.xaxis.set_major_locator(mdates.YearLocator(3,month=1,day=1))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
# grid lines
ax.xaxis.grid(False,'minor') # turn off minor tic grid lines
ax.xaxis.grid(True,'major') # turn on major tic grid lines
ax.yaxis.grid(False,'minor') # turn off minor tic grid lines
ax.yaxis.grid(True,'major') # turn on major tic grid lines
plt.xlabel('Year')
plt.ylabel('Total Number of Death per Million people')
plt.title('Total Number of Death per Year')
Out[822]:
<matplotlib.text.Text at 0x144ff3410>