Data Analysis With Python: Analysis of gun violence incidents in the USA.
Tags: python, datascience, 100daysofcode, web3
Published: 2022-06-25 23:01:30

After the school shooting that happened some weeks ago in Uvalde, Texas, I was prompted to carry some data analysis on gun violence incidents in the USA. 
Read my findings here.

         **************

The dataset for this project contains records of gun violence incidents across the 50 states of the United States of America within the period of **December 28, 2018 to June 20, 2022.**
Data cleaning, analysis and visualization was done using python. The analysis provides answers to some important questions and to get an understanding of the dataset.

**Data Structure:**
Columns in the dataset include; Incident ID, Incident Date, State, City and the Address where the gun violence incident happened.

- The necessary python libraries needed to carry out this analysis was imported into the python IDLE (Jupyter Notebook), And the dataset was loaded in to begin analysis.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/028pr26yckdbr42zzfu7.jpeg)

- Total numbers of column and rows present in the dataset shows 2000 rows and 7 columns.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u75tnkeyjb3e6vp0204k.jpeg)

- 10 random samples of the dataset to see what the dataset looks like.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7hqhmudmx9prqab2hsus.jpeg)


**Data Cleaning** 
Data cleaning was done using the python pandas library in order to “clean “ the dataset and prepare it for analysis.

- Checking for missing values in the dataset 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zh1tyxd8m2nzetf7osw.jpeg)
The image above shows the dataset had missing values in the “Address” column, this missing values were then replaced with “not available “, since we can not replace the missing addresses  with any random address.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1aysndlgtepwfybygn6w.jpeg)


- Checking for duplicates in the dataset to avoid inaccuracy in the results.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mw4q95hqc69sd05yzeyo.jpeg)
The image above shows there were no duplicates in the dataset.
Superb!!!



**Data Analysis and Exploration** 
Analysis was done to answer some key questions and to get useful information.
1) Total number of gun violence incidents in the USA within the period of this record; December 28, 2018 to June 20, 2022.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9b3zvjlzmhojxz4qlm3m.jpeg)

The analysis shows there were 2000 gun violence incidents in the USA within the period stated above.

2) Total number of people killed within the period:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oykhsqul71imrrtemk67.jpeg)

Analysis shows, 2003 people were killed within the period of this record.

3) Total number of people injured.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42s5jocz2a68inek03an.jpeg)

8299 people were injured due to gun violence incident within the period of this record.


4) Top ten states with the most gun violence incidents 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oi4ed2gynpq5ungxlkdf.jpeg)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1frdhy4xi8l23tuaacfx.jpeg)
I was particularly surprised by this result, I really didn’t expect Illinois to  top this chart. This further shows, Data analysis gives result based on facts and not intuition.

5) Bottom ten state with the LEAST gun violence incident.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr236bhzx8rl78a1l41z.jpeg)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1u459fakctd0vif8ghaz.jpeg)

Wyoming, Maine and New Hampshire had just 1 gun violence incidents within the period.

6) Top ten states with the most deaths:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xx3ibvnlqx0w276aq3vq.jpeg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bu6ys4cnpaq9xheaaeh.jpeg)
Texas had the most deaths within this period, with a total of 231 people killed due to gun violence incidents.
Crazy!

7) Top ten city with the most gun violence incident:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h53ho16tw14v5ijc3ntz.jpeg)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg0897l3y6we5dmyyyj6.jpeg)
Chicago, A city in Illinois had the most gun violence incidents across all cities in the USA.

8) Bottom five city with the least incidents:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hazkqt2kmz4hya3olcn9.jpeg)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxyr0809p3yjwdnj6jzr.jpeg)

Lima, salt lake, cleavland, Inkster and West Jefferson were the cities with least incidents.

9) Top five addresses with the most gun violence incidents:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/070nx6aleot7zbl3w88b.jpeg)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4ps5lgwc1o1ysexybmq.jpeg)

NB: four rows in the address column were missing and were replaced with “not available” as explained earlier, hence the not available in the image above. The other four addresses had the most gun violence incidents within the period of this record.

             *************

To view the entire code for this project, please check out my GitHub profile for the Jupyter notebook: https://github.com/heyfunmi/Gun-violence-Analysis

_Thank you for reading_!

For comments and suggestions, please reach me via: heyfunmi@gmail.com