Analysis of conflicts in Africa 1997 - 2017

- 24 mins
import pandas as pd

Context

The Armed Conflict Location and Event Data Project is designed for disaggregated conflict analysis and crisis mapping. This dataset codes the dates and locations of all reported political violence and protest events in dozens of developing countries in Africa. Political violence and protest includes events that occur within civil wars and periods of instability, public protest and regime breakdown. The project covers all African countries from 1997 to 2017.

Content

These data contain information on:

Event data are derived from a variety of sources including reports from developing countries and local media, humanitarian agencies, and research publications. Please review the codebook and user guide for additional information: the codebook is for coders and users of ACLED, whereas the brief guide for users reviews important information for downloading, reviewing and using ACLED data. A specific user guide for development and humanitarian practitioners is also available, as is a guide to our sourcing materials.

Acknowledgements:

ACLED is directed by Prof. Clionadh Raleigh (University of Sussex). It is operated by senior research manager Andrea Carboni (University of Sussex) for Africa and Hillary Tanoff for South and South-East Asia. The data collection involves several research analysts, including Charles Vannice, James Moody, Daniel Wigmore-Shepherd, Andrea Carboni, Matt Batten-Carew, Margaux Pinaud, Roudabeh Kishi, Helen Morris, Braden Fuller, Daniel Moody and others. Please cite: Raleigh, Clionadh, Andrew Linke, Håvard Hegre and Joakim Karlsen. 2010. Introducing ACLED-Armed Conflict Location and Event Data. Journal of Peace Research 47(5) 651-660.

Data Source

The Dataset for this analysis can be gotten on Kaggle Website

About The Dataset

data = pd.read_csv('african_conflicts.csv')
/home/anaconda/.conda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2717: DtypeWarning: Columns (21,23) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)

numbers of rows and columns in the dataset

data.shape
(165808, 28)

First five rows in the dataset

pandas.set_option('display.max_columns', None)
data.head()
ACTOR1 ACTOR1_ID ACTOR2 ACTOR2_ID ACTOR_DYAD_ID ADMIN1 ADMIN2 ADMIN3 ALLY_ACTOR_1 ALLY_ACTOR_2 COUNTRY EVENT_DATE EVENT_ID_CNTY EVENT_ID_NO_CNTY EVENT_TYPE FATALITIES GEO_PRECISION GWNO INTER1 INTER2 INTERACTION LATITUDE LOCATION LONGITUDE NOTES SOURCE TIME_PRECISION YEAR
0 Police Forces of Algeria (1999-) NaN Civilians (Algeria) NaN NaN Tizi Ouzou Beni-Douala NaN NaN Berber Ethnic Group (Algeria) Algeria 18/04/2001 1416RTA NaN Violence against civilians 1 1 615 1 7 17 36.61954 Beni Douala 4.08282 A Berber student was shot while in police cust... Associated Press Online 1 2001
1 Rioters (Algeria) NaN Police Forces of Algeria (1999-) NaN NaN Tizi Ouzou Tizi Ouzou NaN Berber Ethnic Group (Algeria) NaN Algeria 19/04/2001 2229RTA NaN Riots/Protests 0 3 615 5 1 15 36.71183 Tizi Ouzou 4.04591 Riots were reported in numerous villages in Ka... Kabylie report 1 2001
2 Protesters (Algeria) NaN NaN NaN NaN Bejaia Amizour NaN Students (Algeria) NaN Algeria 20/04/2001 2230RTA NaN Riots/Protests 0 1 615 6 0 60 36.64022 Amizour 4.90131 Students protested in the Amizour area. At lea... Crisis Group 1 2001
3 Rioters (Algeria) NaN Police Forces of Algeria (1999-) NaN NaN Bejaia Amizour NaN Berber Ethnic Group (Algeria) NaN Algeria 21/04/2001 2231RTA NaN Riots/Protests 0 1 615 5 1 15 36.64022 Amizour 4.90131 Rioters threw molotov cocktails, rocks and bur... Kabylie report 1 2001
4 Rioters (Algeria) NaN Police Forces of Algeria (1999-) NaN NaN Tizi Ouzou Beni-Douala NaN Berber Ethnic Group (Algeria) NaN Algeria 21/04/2001 2232RTA NaN Riots/Protests 0 1 615 5 1 15 36.61954 Beni Douala 4.08282 Rioters threw molotov cocktails, rocks and bur... Kabylie report 1 2001

the dataset contains more than 165 thousands rows and 28 columns. we will extract columns of interest for this analysis

we extract columns of interests

cols = ['ACTOR1','ACTOR2','ALLY_ACTOR_1','ALLY_ACTOR_2','COUNTRY','EVENT_DATE','EVENT_TYPE','LOCATION','NOTES','SOURCE']
len(cols) ### we will extract ten columns for analysis
10
data = data[cols]
data.columns ## now we have 10 columns to work with
Index([u'ACTOR1', u'ACTOR2', u'ALLY_ACTOR_1', u'ALLY_ACTOR_2', u'COUNTRY',
       u'EVENT_DATE', u'EVENT_TYPE', u'LOCATION', u'NOTES', u'SOURCE'],
      dtype='object')

we display first five rows again

data.head()
ACTOR1 ACTOR2 ALLY_ACTOR_1 ALLY_ACTOR_2 COUNTRY EVENT_DATE EVENT_TYPE LOCATION NOTES SOURCE
0 Police Forces of Algeria (1999-) Civilians (Algeria) NaN Berber Ethnic Group (Algeria) Algeria 18/04/2001 Violence against civilians Beni Douala A Berber student was shot while in police cust... Associated Press Online
1 Rioters (Algeria) Police Forces of Algeria (1999-) Berber Ethnic Group (Algeria) NaN Algeria 19/04/2001 Riots/Protests Tizi Ouzou Riots were reported in numerous villages in Ka... Kabylie report
2 Protesters (Algeria) NaN Students (Algeria) NaN Algeria 20/04/2001 Riots/Protests Amizour Students protested in the Amizour area. At lea... Crisis Group
3 Rioters (Algeria) Police Forces of Algeria (1999-) Berber Ethnic Group (Algeria) NaN Algeria 21/04/2001 Riots/Protests Amizour Rioters threw molotov cocktails, rocks and bur... Kabylie report
4 Rioters (Algeria) Police Forces of Algeria (1999-) Berber Ethnic Group (Algeria) NaN Algeria 21/04/2001 Riots/Protests Beni Douala Rioters threw molotov cocktails, rocks and bur... Kabylie report

lets first check the number of countries embroiled in conflict across Africa

num_conflict = data.COUNTRY.value_counts()
num_conflict.count()
50

we check how each countries are affected

num_conflict
Somalia                         25232
Democratic Republic of Congo    12294
Nigeria                         12253
Sudan                           12018
South Africa                    10887
Egypt                            9290
Burundi                          7396
Libya                            6532
Zimbabwe                         6001
Kenya                            5812
Algeria                          5309
Uganda                           5185
South Sudan                      5144
Ethiopia                         5035
Sierra Leone                     4669
Tunisia                          4493
Central African Republic         3973
Angola                           3181
Ivory Coast                      1804
Mali                             1753
Liberia                          1369
Morocco                          1355
Zambia                           1289
Senegal                          1132
Madagascar                       1064
Burkina Faso                     1032
Cameroon                          937
Guinea                            894
Mozambique                        886
Namibia                           754
Tanzania                          746
Chad                              732
Ghana                             671
Niger                             660
Rwanda                            633
Republic of Congo                 473
Mauritania                        467
Malawi                            434
Eritrea                           408
Togo                              258
Guinea-Bissau                     233
Gabon                             215
Swaziland                         198
Gambia                            190
Benin                             187
Lesotho                           118
Djibouti                          112
Botswana                           53
Equatorial Guinea                  46
Mozambique                          1
Name: COUNTRY, dtype: int64
import matplotlib.pyplot as plt
%matplotlib inline
ax = num_conflict.plot(kind='bar',figsize=(35,17),fontsize=(30))
plt.title("conflicts in Africa (1997-2017)", fontname='Ubuntu', fontsize=38,
          fontstyle='italic', fontweight='normal',color='green')
<matplotlib.text.Text at 0xac7b90ec>

image

we inspect event type to see kind of conflict that is common
cm_conflict = data.EVENT_TYPE.value_counts()
cm_conflict
Riots/Protests                                47224
Violence against civilians                    45021
Battle-No change of territory                 44005
Strategic development                         10923
Remote violence                               10456
Battle-Government regains territory            2632
Non-violent transfer of territory              2566
Battle-Non-state actor overtakes territory     2135
Headquarters or base established                771
Remote Violence                                  30
Violence Against Civilians                       21
Battle-no change of territory                    16
Strategic Development                             7
Strategic development                             1
Name: EVENT_TYPE, dtype: int64

Some event type are not unique!!! lets convert the whole string to lower and then count again, we will also strip white space as well to avoid duplicate

import string
a = data.EVENT_TYPE.apply(string.lower).apply(string.strip).value_counts()
a
riots/protests                                47224
violence against civilians                    45042
battle-no change of territory                 44021
strategic development                         10931
remote violence                               10486
battle-government regains territory            2632
non-violent transfer of territory              2566
battle-non-state actor overtakes territory     2135
headquarters or base established                771
Name: EVENT_TYPE, dtype: int64

now we can visualize event type

ax = a.plot(kind='bar',figsize=(16,6),fontsize=(20))
plt.xticks(rotation=70,fontsize=(17))
plt.title("conflicts Type in Africa (1997-2017)", fontname='Ubuntu', fontsize=20,
          fontstyle='italic', fontweight='normal',color='green')
<matplotlib.text.Text at 0xac53ac8c>

image

which year recorded highest conflict

data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 165808 entries, 0 to 165807
Data columns (total 10 columns):
ACTOR1          165808 non-null object
ACTOR2          122255 non-null object
ALLY_ACTOR_1    28144 non-null object
ALLY_ACTOR_2    19651 non-null object
COUNTRY         165808 non-null object
EVENT_DATE      165808 non-null object
EVENT_TYPE      165808 non-null object
LOCATION        165805 non-null object
NOTES           155581 non-null object
SOURCE          165635 non-null object
dtypes: object(10)
memory usage: 6.3+ MB
we first convert the date and year to datatime
import datetime
data['EVENT_DATE'] = pd.to_datetime(data['EVENT_DATE'],dayfirst=True)
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 165808 entries, 0 to 165807
Data columns (total 10 columns):
ACTOR1          165808 non-null object
ACTOR2          122255 non-null object
ALLY_ACTOR_1    28144 non-null object
ALLY_ACTOR_2    19651 non-null object
COUNTRY         165808 non-null object
EVENT_DATE      165808 non-null datetime64[ns]
EVENT_TYPE      165808 non-null object
LOCATION        165805 non-null object
NOTES           155581 non-null object
SOURCE          165635 non-null object
dtypes: datetime64[ns](1), object(9)
memory usage: 7.0+ MB
data_n = data.set_index(data.EVENT_DATE)
data_n['counter'] = 0 #### we create new column to hold number of conflict per year
data_n = data_n['counter']
data_n = pd.DataFrame(data_n)
con_yr = data_n.resample('Y').count()
t = (range(1997,2018))
t = tuple(t)
ax = con_yr.plot(kind='bar',figsize=(15,6),fontsize=(18))
plt.title('Annual conflict 1997-2017',fontsize=(16))
ax.set_xticklabels(t,rotation=30)
ax.grid()

image

2016 was the most troubled year

Conflict according to region of Africa

data.COUNTRY.unique()
array(['Algeria', 'Angola', 'Benin', 'Burkina Faso', 'Burundi',
       'Cameroon', 'Central African Republic', 'Chad',
       'Democratic Republic of Congo', 'Egypt', 'Equatorial Guinea',
       'Eritrea', 'Ethiopia', 'Gabon', 'Gambia', 'Ghana', 'Guinea',
       'Guinea-Bissau', 'Ivory Coast', 'Kenya', 'Lesotho', 'Liberia',
       'Libya', 'Madagascar', 'Malawi', 'Mali', 'Mauritania', 'Morocco',
       'Mozambique', 'Namibia', 'Niger', 'Nigeria', 'Republic of Congo',
       'Rwanda', 'Senegal', 'Sierra Leone', 'Somalia', 'South Africa',
       'South Sudan', 'Sudan', 'Swaziland', 'Tanzania', 'Togo', 'Tunisia',
       'Uganda', 'Zambia', 'Zimbabwe', 'Botswana', 'Djibouti',
       'Mozambique '], dtype=object)
region = {
    'north':['Algeria','Egypt','Morocco','Sudan','Tunisia','Western Sahara','Libya','Mauritania'],
    'east':['Burundi','Comoros','Djibouti','Eritrea','Ethiopia','Kenya','Zambia',
            'Madagascar','Malawi','Mauritius','Mayotte','Mozambique','Uganda',
            'Reunion','Rwanda','Seychelles','Somalia','South Sudan','Tanzania','Zimbabwe'],
    'west':['Benin','Burkina Faso','Cape Verde','Ivory Coast','Gambia',
            'Ghana','Guinea','Guinea-Bissau','Liberia','Mali',
            'Mauritania','Niger','Nigeria','Saint Helena','Senegal','Sierra Leone',
            'Togo'],
    'central':['Angola','Cameroon','Central African Republic','Chad',
               'Democratic Republic of Congo','Republic of Congo',
               'Equatorial Guinea','Gabon'],

    'south':['Botswana','Lesotho','Namibia','South Africa''Swaziland','Angola','Zambia']
}
def mapper(country):
    if string.strip(country) in region['north'] or string.capitalize(country) in region['north']:
        return 1
    if string.strip(country) in region['east'] or string.capitalize(country) in region['east']:
        return 2
    if string.strip(country) in region['west'] or string.capitalize(country) in region['west']:
        return 3
    if string.strip(country) in region['central'] or string.capitalize(country) in region['central']:
        return 4
    if string.strip(country) in region['south'] or string.capitalize(country) in region['south']:
        return 5
    return 5 ### South africa and Swaziland here too
data_region = data
data_region.COUNTRY = data.COUNTRY.apply(mapper)
data_region = data_region.COUNTRY.value_counts()
data_region
2    65378
1    39464
3    27105
4    21851
5    12010
Name: COUNTRY, dtype: int64
data_region = pd.DataFrame(data_region)
data_region['val'] = [2,1,3,4,5]
def mapper(val):
    if val == 1:
        return 'North Africa'
    if val == 2:
        return 'East Africa'
    if val == 3:
        return 'West Africa'
    if val == 4 :
        return 'Central Africa'
    return 'South Africa' 
data_region.val = data_region.val.apply(mapper)
data_region
val REGION
2 65378 East Africa
1 39464 North Africa
3 27105 West Africa
4 21851 Central Africa
5 12010 South Africa

we visulize conflicts in terms of region

data_region.set_index(data_region.val,inplace=True)
del data_region['val']
data_region
val
REGION
East Africa 65378
North Africa 39464
West Africa 27105
Central Africa 21851
South Africa 12010
ax = data_region.COUNTRY.plot(kind='bar',figsize=(16,6))
plt.xticks(fontsize=(24),rotation=30)
plt.tight_layout()
plt.yticks(fontsize=(20))
plt.title('Conflicts in Africa according to region',fontsize=(28))
plt.legend()
plt.grid()

image

Analysis of conflicts that has something to do with Students

we will inspect column Note and we extract any rows that mention student

stud_con = data[(data.NOTES.str.find('students') >=0 ) | (data.NOTES.str.find('Students') >=0 )]

lets count the number of rows returned

stud_con.shape
(5474, 28)
## more than five thousand

stud_con.head()
ACTOR1 ACTOR1_ID ACTOR2 ACTOR2_ID ACTOR_DYAD_ID ADMIN1 ADMIN2 ADMIN3 ALLY_ACTOR_1 ALLY_ACTOR_2 COUNTRY EVENT_DATE EVENT_ID_CNTY EVENT_ID_NO_CNTY EVENT_TYPE FATALITIES GEO_PRECISION GWNO INTER1 INTER2 INTERACTION LATITUDE LOCATION LONGITUDE NOTES SOURCE TIME_PRECISION YEAR
2 Protesters (Algeria) NaN NaN NaN NaN Bejaia Amizour NaN Students (Algeria) NaN Algeria 20/04/2001 2230RTA NaN Riots/Protests 0 1 615 6 0 60 36.64022 Amizour 4.90131 Students protested in the Amizour area. At lea... Crisis Group 1 2001
27 Protesters (Algeria) NaN Police Forces of Algeria (1999-) NaN NaN Oran Oran NaN Students (Algeria) NaN Algeria 3/05/2001 2243RTA NaN Riots/Protests 0 1 615 6 1 16 35.6911 Oran -0.6417 Students demonstrated in Oran despite signific... Kabylie report 1 2001
28 Protesters (Algeria) NaN NaN NaN NaN Alger Sidi MHamed NaN Students (Algeria) NaN Algeria 4/05/2001 2244RTA NaN Riots/Protests 0 1 615 6 0 60 36.7525 Algiers 3.04197 As many as 10,000 students protested at the go... Kabylie report 1 2001
52 Protesters (Algeria) NaN NaN NaN NaN Alger Sidi MHamed NaN Students (Algeria) NaN Algeria 29/05/2001 1450RTA NaN Riots/Protests 0 1 615 6 0 60 36.7525 Algiers 3.04197 Students protested in the Algerian capital to ... Associated Press Online 1 2001
155 Protesters (Algeria) NaN NaN NaN NaN Tizi Ouzou Tizi Ouzou NaN Berber Ethnic Group (Algeria); Students (Algeria) NaN Algeria 15/04/2002 2622RTA NaN Riots/Protests 0 3 615 6 0 60 36.71183 Tizi Ouzou 4.04591 Students protested and boycotted classes to de... Kabylie report 3 2002
which country has highest number of student conflict?
stud_con.COUNTRY.value_counts()
South Africa                    1167
Egypt                            521
Ethiopia                         497
Sudan                            481
Nigeria                          461
Kenya                            318
Uganda                           202
Tunisia                          177
Democratic Republic of Congo     140
Algeria                          126
Burkina Faso                     115
Burundi                          106
Senegal                          102
Zambia                            96
Zimbabwe                          80
Ivory Coast                       79
Somalia                           75
Malawi                            71
Madagascar                        66
Morocco                           61
Liberia                           60
Central African Republic          53
Niger                             41
Guinea                            32
Gabon                             32
Swaziland                         31
South Sudan                       31
Namibia                           29
Togo                              29
Chad                              27
Sierra Leone                      23
Libya                             18
Ghana                             17
Tanzania                          17
Mauritania                        15
Gambia                             9
Rwanda                             9
Cameroon                           9
Mali                               8
Benin                              8
Republic of Congo                  8
Angola                             7
Botswana                           7
Mozambique                         4
Guinea-Bissau                      3
Equatorial Guinea                  2
Djibouti                           2
Eritrea                            1
Lesotho                            1
Name: COUNTRY, dtype: int64
## south africa has the highest number of student conflict or conflict that has something to
## do with student
std_con = stud_con.COUNTRY.value_counts()
ax = std_con.plot(kind='bar',figsize=(25,10),fontsize=(30))
plt.title('student conflict---countries wise',fontsize=(30))
<matplotlib.text.Text at 0xa7fde38c>

image

conflict involving women

wn = data[(data.NOTES.str.find('women') >=0 ) | (data.NOTES.str.find('Women') >=0 )|(data.NOTES.str.find('Woman') >=0 )|(data.NOTES.str.find('woman') >=0 )]
len(wn) # it return more than 3000 rows
3944
wn.head(2)
ACTOR1 ACTOR1_ID ACTOR2 ACTOR2_ID ACTOR_DYAD_ID ADMIN1 ADMIN2 ADMIN3 ALLY_ACTOR_1 ALLY_ACTOR_2 COUNTRY EVENT_DATE EVENT_ID_CNTY EVENT_ID_NO_CNTY EVENT_TYPE FATALITIES GEO_PRECISION GWNO INTER1 INTER2 INTERACTION LATITUDE LOCATION LONGITUDE NOTES SOURCE TIME_PRECISION YEAR
78 Protesters (Algeria) NaN NaN NaN NaN Alger Cheraga NaN NaN NaN Algeria 19/06/2001 2601RTA NaN Riots/Protests 0 1 615 6 0 60 36.80277 Ain Benian 2.92185 100 women gathered in Ain Benian, west of Algi... Kabylie report 1 2001
410 Protesters (Algeria) NaN Police Forces of Algeria (1999-) NaN NaN Bejaia Bejaia NaN SNATEGZ: National Autonomous Union of Sonelgaz... NaN Algeria 22/03/2017 3605RTA NaN Violence against civilians 0 1 615 6 1 16 36.75 Bejaia 5.0833 Security forces attacked the participants of t... Arab Trade Union Confederation; El Watan 1 2017
wn.COUNTRY.value_counts()
Sudan                           651
Somalia                         492
Democratic Republic of Congo    416
Nigeria                         318
South Africa                    289
South Sudan                     223
Central African Republic        179
Burundi                         160
Egypt                           140
Kenya                           138
Zimbabwe                        137
Tunisia                         112
Uganda                           88
Algeria                          87
Libya                            70
Morocco                          44
Ivory Coast                      32
Ghana                            31
Ethiopia                         26
Senegal                          25
Namibia                          24
Mali                             21
Cameroon                         20
Liberia                          18
Angola                           17
Guinea                           17
Mauritania                       16
Mozambique                       16
Zambia                           16
Burkina Faso                     15
Madagascar                       14
Rwanda                           13
Malawi                           12
Sierra Leone                     10
Tanzania                         10
Niger                             9
Republic of Congo                 7
Swaziland                         6
Chad                              5
Eritrea                           4
Togo                              4
Botswana                          4
Djibouti                          2
Gambia                            2
Lesotho                           1
Gabon                             1
Guinea-Bissau                     1
Equatorial Guinea                 1
Name: COUNTRY, dtype: int64
ax = wn.COUNTRY.value_counts().plot(kind='bar',figsize=(20,8),fontsize=(20))

image

SUMMARIES BASED ON THE DATASET


Mustapha Omotosho

Mustapha Omotosho

constant learner,machine learning enthusiast,huge Barcelona fan

comments powered by Disqus
rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora