Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
import numpy as np,pandas as pd
import matplotlib.pyplot as plt, seaborn as sns
sns.set_style("darkgrid")
import warnings
warnings.simplefilter("ignore")
pd.set_option("display.max_columns",500)
pd.set_option("display.max_rows",500)
terror_data = pd.read_csv("globalterrorism.csv", engine='python',encoding='latin1')
terror_data.head()
def info_terror_data(dataframe):
print("Information of this dataset",dataframe.info()) #Information of terror_data
print("\nShape of the dataset is:",dataframe.shape) #Shape of terror_data
print("\nNull Values in this dataset are:\n",dataframe.isnull().sum()) #Checking null values
print("\nNumerical description of this dataset is:\n",dataframe.describe()) #Numerical Description
info_terror_data(terror_data)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 181691 entries, 0 to 181690
Columns: 135 entries, eventid to related
dtypes: float64(55), int64(22), object(58)
memory usage: 187.1+ MB
Information of this dataset None
Shape of the dataset is: (181691, 135)
Null Values in this dataset are:
eventid 0
iyear 0
imonth 0
iday 0
approxdate 172452
extended 0
resolution 179471
country 0
country_txt 0
region 0
region_txt 0
provstate 421
city 434
latitude 4556
longitude 4557
specificity 6
vicinity 0
location 126196
summary 66129
crit1 0
crit2 0
crit3 0
doubtterr 1
alternative 152680
alternative_txt 152680
multiple 1
success 0
suicide 0
attacktype1 0
attacktype1_txt 0
attacktype2 175377
attacktype2_txt 175377
attacktype3 181263
attacktype3_txt 181263
targtype1 0
targtype1_txt 0
targsubtype1 10373
targsubtype1_txt 10373
corp1 42550
target1 636
natlty1 1559
natlty1_txt 1559
targtype2 170547
targtype2_txt 170547
targsubtype2 171006
targsubtype2_txt 171006
corp2 171574
target2 170671
natlty2 170863
natlty2_txt 170863
targtype3 180515
targtype3_txt 180515
targsubtype3 180594
targsubtype3_txt 180594
corp3 180665
target3 180516
natlty3 180544
natlty3_txt 180544
gname 0
gsubname 175801
gname2 179678
gsubname2 181531
gname3 181367
gsubname3 181671
motive 131130
guncertain1 380
guncertain2 179736
guncertain3 181371
individual 0
nperps 71115
nperpcap 69489
claimed 66120
claimmode 162608
claimmode_txt 162608
claim2 179801
claimmode2 181075
claimmode2_txt 181075
claim3 181373
claimmode3 181558
claimmode3_txt 181558
compclaim 176852
weaptype1 0
weaptype1_txt 0
weapsubtype1 20768
weapsubtype1_txt 20768
weaptype2 168564
weaptype2_txt 168564
weapsubtype2 170149
weapsubtype2_txt 170149
weaptype3 179828
weaptype3_txt 179828
weapsubtype3 179998
weapsubtype3_txt 179998
weaptype4 181618
weaptype4_txt 181618
weapsubtype4 181621
weapsubtype4_txt 181621
weapdetail 67670
nkill 10313
nkillus 64446
nkillter 66958
nwound 16311
nwoundus 64702
nwoundte 69143
property 0
propextent 117626
propextent_txt 117626
propvalue 142702
propcomment 123732
ishostkid 178
nhostkid 168119
nhostkidus 168174
nhours 177628
ndays 173567
divert 181367
kidhijcountry 178386
ransom 104310
ransomamt 180341
ransomamtus 181128
ransompaid 180917
ransompaidus 181139
ransomnote 181177
hostkidoutcome 170700
hostkidoutcome_txt 170700
nreleased 171291
addnotes 153402
scite1 66191
scite2 104758
scite3 138175
dbsource 0
INT_LOG 0
INT_IDEO 0
INT_MISC 0
INT_ANY 0
related 156653
dtype: int64
Numerical description of this dataset is:
eventid iyear imonth iday \
count 1.816910e+05 181691.000000 181691.000000 181691.000000
mean 2.002705e+11 2002.638997 6.467277 15.505644
std 1.325957e+09 13.259430 3.388303 8.814045
min 1.970000e+11 1970.000000 0.000000 0.000000
25% 1.991021e+11 1991.000000 4.000000 8.000000
50% 2.009022e+11 2009.000000 6.000000 15.000000
75% 2.014081e+11 2014.000000 9.000000 23.000000
max 2.017123e+11 2017.000000 12.000000 31.000000
extended country region latitude \
count 181691.000000 181691.000000 181691.000000 177135.000000
mean 0.045346 131.968501 7.160938 23.498343
std 0.208063 112.414535 2.933408 18.569242
min 0.000000 4.000000 1.000000 -53.154613
25% 0.000000 78.000000 5.000000 11.510046
50% 0.000000 98.000000 6.000000 31.467463
75% 0.000000 160.000000 10.000000 34.685087
max 1.000000 1004.000000 12.000000 74.633553
longitude specificity vicinity crit1 \
count 1.771340e+05 181685.000000 181691.000000 181691.000000
mean -4.586957e+02 1.451452 0.068297 0.988530
std 2.047790e+05 0.995430 0.284553 0.106483
min -8.618590e+07 1.000000 -9.000000 0.000000
25% 4.545640e+00 1.000000 0.000000 1.000000
50% 4.324651e+01 1.000000 0.000000 1.000000
75% 6.871033e+01 1.000000 0.000000 1.000000
max 1.793667e+02 5.000000 1.000000 1.000000
crit2 crit3 doubtterr alternative \
count 181691.000000 181691.000000 181690.000000 29011.000000
mean 0.993093 0.875668 -0.523171 1.292923
std 0.082823 0.329961 2.455819 0.703729
min 0.000000 0.000000 -9.000000 1.000000
25% 1.000000 1.000000 0.000000 1.000000
50% 1.000000 1.000000 0.000000 1.000000
75% 1.000000 1.000000 0.000000 1.000000
max 1.000000 1.000000 1.000000 5.000000
multiple success suicide attacktype1 \
count 181690.000000 181691.000000 181691.000000 181691.000000
mean 0.137773 0.889598 0.036507 3.247547
std 0.344663 0.313391 0.187549 1.915772
min 0.000000 0.000000 0.000000 1.000000
25% 0.000000 1.000000 0.000000 2.000000
50% 0.000000 1.000000 0.000000 3.000000
75% 0.000000 1.000000 0.000000 3.000000
max 1.000000 1.000000 1.000000 9.000000
attacktype2 attacktype3 targtype1 targsubtype1 natlty1 \
count 6314.000000 428.000000 181691.000000 171318.000000 180132.000000
mean 3.719512 5.245327 8.439719 46.971474 127.686441
std 2.272023 2.246642 6.653838 30.953357 89.299120
min 1.000000 1.000000 1.000000 1.000000 4.000000
25% 2.000000 2.000000 3.000000 22.000000 83.000000
50% 2.000000 7.000000 4.000000 35.000000 101.000000
75% 7.000000 7.000000 14.000000 74.000000 173.000000
max 9.000000 8.000000 22.000000 113.000000 1004.000000
targtype2 targsubtype2 natlty2 targtype3 targsubtype3 \
count 11144.000000 10685.000000 10828.000000 1176.000000 1097.000000
mean 10.247218 55.311652 131.179442 10.021259 55.548769
std 5.709076 25.640310 125.951485 5.723447 26.288955
min 1.000000 1.000000 4.000000 1.000000 1.000000
25% 4.000000 34.000000 92.000000 3.000000 33.000000
50% 14.000000 67.000000 98.000000 14.000000 67.000000
75% 14.000000 69.000000 182.000000 14.000000 73.000000
max 22.000000 113.000000 1004.000000 22.000000 113.000000
natlty3 guncertain1 guncertain2 guncertain3 individual \
count 1147.000000 181311.000000 1955.000000 320.000000 181691.000000
mean 144.564952 0.081440 0.265473 0.193750 0.002950
std 163.299295 0.273511 0.441698 0.395854 0.054234
min 4.000000 0.000000 0.000000 0.000000 0.000000
25% 75.000000 0.000000 0.000000 0.000000 0.000000
50% 110.000000 0.000000 0.000000 0.000000 0.000000
75% 182.000000 0.000000 1.000000 0.000000 0.000000
max 1004.000000 1.000000 1.000000 1.000000 1.000000
nperps nperpcap claimed claimmode claim2 \
count 110576.000000 112202.000000 115571.000000 19083.000000 1890.000000
mean -65.361154 -1.517727 0.049666 7.022848 0.247619
std 216.536633 12.830346 1.093195 2.476851 0.974018
min -99.000000 -99.000000 -9.000000 1.000000 -9.000000
25% -99.000000 0.000000 0.000000 6.000000 0.000000
50% -99.000000 0.000000 0.000000 8.000000 0.000000
75% 1.000000 0.000000 0.000000 8.000000 1.000000
max 25000.000000 406.000000 1.000000 10.000000 1.000000
claimmode2 claim3 claimmode3 compclaim weaptype1 \
count 616.000000 318.000000 133.000000 4839.000000 181691.000000
mean 7.176948 0.411950 6.729323 -6.296342 6.447325
std 2.783725 0.492962 2.908003 4.234620 2.173435
min 1.000000 0.000000 1.000000 -9.000000 1.000000
25% 6.000000 0.000000 4.000000 -9.000000 5.000000
50% 7.000000 0.000000 7.000000 -9.000000 6.000000
75% 10.000000 1.000000 9.000000 0.000000 6.000000
max 10.000000 1.000000 10.000000 1.000000 13.000000
weapsubtype1 weaptype2 weapsubtype2 weaptype3 weapsubtype3 \
count 160923.000000 13127.000000 11542.000000 1863.000000 1693.000000
mean 11.117162 6.812524 10.754029 6.911433 11.643237
std 6.495612 2.277081 7.594574 2.177956 8.493166
min 1.000000 1.000000 1.000000 2.000000 1.000000
25% 5.000000 5.000000 5.000000 5.000000 4.000000
50% 12.000000 6.000000 7.000000 6.000000 7.000000
75% 16.000000 8.000000 18.000000 9.000000 20.000000
max 31.000000 13.000000 31.000000 13.000000 28.000000
weaptype4 weapsubtype4 nkill nkillus nkillter \
count 73.000000 70.000000 171378.000000 117245.000000 114733.000000
mean 6.246575 10.842857 2.403272 0.045981 0.508058
std 1.507212 8.192672 11.545741 5.681854 4.199937
min 5.000000 2.000000 0.000000 0.000000 0.000000
25% 5.000000 3.000000 0.000000 0.000000 0.000000
50% 6.000000 9.500000 0.000000 0.000000 0.000000
75% 6.000000 16.000000 2.000000 0.000000 0.000000
max 12.000000 28.000000 1570.000000 1360.000000 500.000000
nwound nwoundus nwoundte property \
count 165380.000000 116989.000000 112548.000000 181691.000000
mean 3.167668 0.038944 0.107163 -0.544556
std 35.949392 3.057361 1.488881 3.122889
min 0.000000 0.000000 0.000000 -9.000000
25% 0.000000 0.000000 0.000000 0.000000
50% 0.000000 0.000000 0.000000 1.000000
75% 2.000000 0.000000 0.000000 1.000000
max 8191.000000 751.000000 200.000000 1.000000
propextent propvalue ishostkid nhostkid nhostkidus \
count 64065.000000 3.898900e+04 181513.000000 13572.000000 13517.000000
mean 3.295403 2.088119e+05 0.059054 4.533230 -0.353999
std 0.486912 1.552463e+07 0.461244 202.316386 6.835645
min 1.000000 -9.900000e+01 -9.000000 -99.000000 -99.000000
25% 3.000000 -9.900000e+01 0.000000 1.000000 0.000000
50% 3.000000 -9.900000e+01 0.000000 2.000000 0.000000
75% 4.000000 1.000000e+03 0.000000 4.000000 0.000000
max 4.000000 2.700000e+09 1.000000 17000.000000 86.000000
nhours ndays ransom ransomamt ransomamtus \
count 4063.000000 8124.000000 77381.000000 1.350000e+03 5.630000e+02
mean -46.793933 -32.516371 -0.145811 3.172530e+06 5.784865e+05
std 82.800405 121.209205 1.207861 3.021157e+07 7.077924e+06
min -99.000000 -99.000000 -9.000000 -9.900000e+01 -9.900000e+01
25% -99.000000 -99.000000 0.000000 0.000000e+00 0.000000e+00
50% -99.000000 -99.000000 0.000000 1.500000e+04 0.000000e+00
75% 0.000000 4.000000 0.000000 4.000000e+05 0.000000e+00
max 999.000000 2454.000000 1.000000 1.000000e+09 1.320000e+08
ransompaid ransompaidus hostkidoutcome nreleased \
count 7.740000e+02 552.000000 10991.000000 10400.000000
mean 7.179437e+05 240.378623 4.629242 -29.018269
std 1.014392e+07 2940.967293 2.035360 65.720119
min -9.900000e+01 -99.000000 1.000000 -99.000000
25% -9.900000e+01 0.000000 2.000000 -99.000000
50% 0.000000e+00 0.000000 4.000000 0.000000
75% 1.273412e+03 0.000000 7.000000 1.000000
max 2.750000e+08 48000.000000 7.000000 2769.000000
INT_LOG INT_IDEO INT_MISC INT_ANY
count 181691.000000 181691.000000 181691.000000 181691.000000
mean -4.543731 -4.464398 0.090010 -3.945952
std 4.543547 4.637152 0.568457 4.691325
min -9.000000 -9.000000 -9.000000 -9.000000
25% -9.000000 -9.000000 0.000000 -9.000000
50% -9.000000 -9.000000 0.000000 0.000000
75% 0.000000 0.000000 0.000000 0.000000
max 1.000000 1.000000 1.000000 1.000000
#Null Values in Percentage
terror_data.isnull().sum() / len(terror_data) * 100
eventid 0.000000
iyear 0.000000
imonth 0.000000
iday 0.000000
approxdate 94.914993
extended 0.000000
resolution 98.778145
country 0.000000
country_txt 0.000000
region 0.000000
region_txt 0.000000
provstate 0.231712
city 0.238867
latitude 2.507554
longitude 2.508104
specificity 0.003302
vicinity 0.000000
location 69.456385
summary 36.396409
crit1 0.000000
crit2 0.000000
crit3 0.000000
doubtterr 0.000550
alternative 84.032781
alternative_txt 84.032781
multiple 0.000550
success 0.000000
suicide 0.000000
attacktype1 0.000000
attacktype1_txt 0.000000
attacktype2 96.524869
attacktype2_txt 96.524869
attacktype3 99.764435
attacktype3_txt 99.764435
targtype1 0.000000
targtype1_txt 0.000000
targsubtype1 5.709144
targsubtype1_txt 5.709144
corp1 23.418882
target1 0.350045
natlty1 0.858050
natlty1_txt 0.858050
targtype2 93.866510
targtype2_txt 93.866510
targsubtype2 94.119136
targsubtype2_txt 94.119136
corp2 94.431755
target2 93.934757
natlty2 94.040431
natlty2_txt 94.040431
targtype3 99.352747
targtype3_txt 99.352747
targsubtype3 99.396228
targsubtype3_txt 99.396228
corp3 99.435305
target3 99.353298
natlty3 99.368708
natlty3_txt 99.368708
gname 0.000000
gsubname 96.758232
gname2 98.892075
gsubname2 99.911938
gname3 99.821675
gsubname3 99.988992
motive 72.171984
guncertain1 0.209146
guncertain2 98.923997
guncertain3 99.823877
individual 0.000000
nperps 39.140629
nperpcap 38.245703
claimed 36.391456
claimmode 89.497003
claimmode_txt 89.497003
claim2 98.959772
claimmode2 99.660963
claimmode2_txt 99.660963
claim3 99.824978
claimmode3 99.926799
claimmode3_txt 99.926799
compclaim 97.336687
weaptype1 0.000000
weaptype1_txt 0.000000
weapsubtype1 11.430396
weapsubtype1_txt 11.430396
weaptype2 92.775096
weaptype2_txt 92.775096
weapsubtype2 93.647456
weapsubtype2_txt 93.647456
weaptype3 98.974633
weaptype3_txt 98.974633
weapsubtype3 99.068198
weapsubtype3_txt 99.068198
weaptype4 99.959822
weaptype4_txt 99.959822
weapsubtype4 99.961473
weapsubtype4_txt 99.961473
weapdetail 37.244553
nkill 5.676120
nkillus 35.470111
nkillter 36.852678
nwound 8.977330
nwoundus 35.611010
nwoundte 38.055270
property 0.000000
propextent 64.739585
propextent_txt 64.739585
propvalue 78.541039
propcomment 68.100236
ishostkid 0.097969
nhostkid 92.530175
nhostkidus 92.560446
nhours 97.763786
ndays 95.528672
divert 99.821675
kidhijcountry 98.180978
ransom 57.410659
ransomamt 99.256980
ransomamtus 99.690133
ransompaid 99.574002
ransompaidus 99.696187
ransomnote 99.717102
hostkidoutcome 93.950719
hostkidoutcome_txt 93.950719
nreleased 94.275996
addnotes 84.430159
scite1 36.430533
scite2 57.657231
scite3 76.049447
dbsource 0.000000
INT_LOG 0.000000
INT_IDEO 0.000000
INT_MISC 0.000000
INT_ANY 0.000000
related 86.219461
dtype: float64
terror_data = terror_data.loc[:, (terror_data.isnull().sum() / len(terror_data) * 100) <= 30]
terror_data.head()