<jupyter_start><jupyter_text>Author : Aravinth.S Data Science and Business Analytics Tasks The Sparks Foundation : Graduate Rotational Internship Program (GRIP) June 2021 Batch Task 4 : Exploratory Data Analysis(Global Terrorism) Problem Statement : As a security/defense analyst, try to find out the hot zone of terrorism.   What all security issues and insights you can derive by EDA?   Importing libraries<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
plt.style.use('ggplot')<jupyter_output><empty_output><jupyter_text>Loading dataset<jupyter_code>df = pd.read_csv('global_terr.csv',encoding='ISO-8859-1')
pd.set_option('display.max_columns',None)
df.head()
df.shape
df.columns<jupyter_output><empty_output><jupyter_text>Rename columns<jupyter_code>df.rename(columns={'iyear':'Year','imonth':'Month','iday':'Day','country_txt':'Country','provstate':'state',
                       'region_txt':'Region','attacktype1_txt':'AttackType','target1':'Target','nkill':'Killed',
                       'nwound':'Wounded','summary':'Summary','gname':'Group','targtype1_txt':'Target_type',
                       'weaptype1_txt':'Weapon_type','motive':'Motive'},inplace=True)
df.columns<jupyter_output><empty_output><jupyter_text>Drop useless columns<jupyter_code>df=df[['Year','Month','Day','Country','state','Region','city','latitude','longitude','AttackType','Killed',
               'Wounded','Target','Summary','Group','Target_type','Weapon_type','Motive']]
df.columns
df.shape
df.info()
df.head(5).T<jupyter_output><empty_output><jupyter_text>Any Missing Values??<jupyter_code>df.isnull().sum()/len(df) *100
df=df.drop(['Motive','Summary'],axis =1)
df.shape<jupyter_output><empty_output><jupyter_text>Exploratory Data Analysis  1.Country Top Countries affected by Terror Attacks<jupyter_code>plt.figure(figsize=(15,10))
country = df['Country'].value_counts().reset_index()
sns.barplot(x='index', y='Country', data =country[:14])
plt.title('Top Countries affected by Terror Attacks')
plt.xlabel('Country name')
plt.ylabel('Number of attacks')
plt.xticks(rotation=45)
plt.show()<jupyter_output><empty_output><jupyter_text>2.City Top Cities affected by Terror Attacks<jupyter_code>city = df['city'].value_counts().reset_index()
plt.figure(figsize=(15,10))

sns.barplot(x='index', y='city', data =city[1:14])
plt.title('Top Cities affected by Terror Attacks')
plt.xlabel('City name')
plt.ylabel('Number of attacks')
plt.xticks(rotation=45)
plt.show()<jupyter_output><empty_output><jupyter_text>3.Region Terrorist Activities by Region<jupyter_code>plt.figure(figsize = (12,10))
sns.barplot(x=df['Region'].value_counts().values, y=df['Region'].value_counts().index)
plt.title('Terrorist Attacks per Region')
plt.show()<jupyter_output><empty_output><jupyter_text>Terrorist Activities by Region year wise<jupyter_code>pd.crosstab(df.Year, df.Region).plot(kind='area',figsize=(15,5))
plt.title('Terrorist Activities by Region year wise')
plt.ylabel('Number of Attacks')
plt.show()<jupyter_output><empty_output><jupyter_text>4. Year Terrorist Attacks in each Year<jupyter_code>plt.figure(figsize=(15,10))
sns.countplot(df['Year'])
plt.xticks(rotation =45)
plt.title('Terrorist Attacks in each Year')
plt.ylabel('Number of Attacks')
# plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>5.People were killed in a Terrorist Attack Peoples were killed in a Terrorist Attack in each Year<jupyter_code>killed=df.groupby('Year').sum()['Killed'].reset_index()
year=df.groupby('Year').size()
year=pd.DataFrame({'Attack': year}) 
year = year.reset_index()
killed= killed.drop(['Year'], axis=1)
new_year=pd.concat([year,killed],axis=1)
plt.figure(figsize=(15,10))
sns.barplot(data = new_year, x='Year', y='Killed')
plt.xticks(rotation =45)
plt.title('Peoples were killed in a Terrorist Attack in each Year')
plt.ylabel('Number of people killed')
plt.xlabel('Year')
plt.show()
new_year.plot(x='Year',figsize=(15, 8))
plt.title('Number of Attack with number of killed ')
plt.show()<jupyter_output><empty_output><jupyter_text>6. Different types of Attack_Type<jupyter_code>plt.figure(figsize=(12,8))
sns.countplot(df['AttackType'])
plt.title('Count Different types of Attack Type')
plt.xticks(rotation =45)
plt.show()<jupyter_output><empty_output><jupyter_text>7.Different Types of Target<jupyter_code>plt.figure(figsize=(15,10))
new_df = df[df['Target']!='Unknown']
sns.barplot(y=new_df['Target_type'].value_counts()[:15].index,x=new_df['Target_type'].value_counts()[:15].values)
plt.title('Different Types of Targets')
plt.show()<jupyter_output><empty_output><jupyter_text>8. Terrorist Organizations  Most Active Terrorist Organizations<jupyter_code>plt.figure(figsize=(15,10))
sns.barplot(y=df['Group'].value_counts()[1:15].index,x=df['Group'].value_counts()[1:15].values)
plt.title('15 Most Active Terrorist Organizations')
plt.xlabel('Number of attacks')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16403280656131225, 'fraction_numerical': 0.01860372074414883, 'mean_word_length': 8.671179883945841, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '234579', 'license': 'MIT', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1734, 'n_words': 295, 'path': 'grip task 4.ipynb', 'repo_name': 'aravi16/Exploratory-Data-Analysis-Global-terrorism-', 'size': '4999'}