In [874]:
%matplotlib inline
import pandas as pd
import numpy as np
In [875]:
raw_df = pd.DataFrame.from_csv('31461-0002-Data.tsv',sep='\t', index_col=None)
# raw_df = raw_df[raw_df['seltrans'] == '1']
# raw_df = raw_df[raw_df['seltrans'] == '1']
# raw_df[['country','year','sa2']]
print raw_df.country.unique()
print raw_df.columns
['Afghanistan' 'Albania' 'Algeria' 'Angola' 'Argentina' 'Armenia'
'Australia' 'Austria' 'Azerbaijan' 'Bahamas' 'Bahrain' 'Bangladesh'
'Barbados' 'Belarus' 'Belgium' 'Belize' 'Benin' 'Bolivia' 'Bosnia-Herz'
'Botswana' 'Brazil' 'Bulgaria' 'Burkina Faso' 'Burundi' 'C. Verde Is.'
'Cambodia' 'Cameroon' 'Canada' 'Cent. Af. Rep.' 'Chad' 'Chile' 'Colombia'
'Comoro Is.' 'Congo' 'Costa Rica' "Cote d'Ivoire" 'Croatia' 'Cuba'
'Cyprus' 'Czech Rep.' 'Denmark' 'Djibouti' 'Dom. Rep.' 'Ecuador' 'Egypt'
'El Salvador' 'Eq. Guinea' 'Estonia' 'Ethiopia' 'FRG/Germany' 'Fiji'
'Finland' 'France' 'GDR' 'Gabon' 'Gambia' 'Georgia' 'Ghana' 'Greece'
'Grenada' 'Guatemala' 'Guinea' 'Guinea-Bissau' 'Guyana' 'Haiti' 'Honduras'
'Hungary' 'Iceland' 'India' 'Indonesia' 'Iran' 'Iraq' 'Ireland' 'Israel'
'Italy' 'Jamaica' 'Japan' 'Jordan' 'Kazakhstan' 'Kenya' 'Kuwait'
'Kyrgyzstan' 'Laos' 'Latvia' 'Lebanon' 'Lesotho' 'Liberia' 'Lithuania'
'Luxembourg' 'Macedonia' 'Madagascar' 'Malawi' 'Malaysia' 'Maldives'
'Mali' 'Malta' 'Mauritania' 'Mauritius' 'Mexico' 'Moldova' 'Mongolia'
'Morocco' 'Mozambique' 'Myanmar' 'Namibia' 'Nepal' 'Netherlands'
'New Zealand' 'Nicaragua' 'Niger' 'Nigeria' 'Norway' 'P. N. Guinea' 'PRK'
'Pakistan' 'Panama' 'Paraguay' 'Peru' 'Philippines' 'Poland' 'Portugal'
'ROK' 'Romania' 'Russia' 'Rwanda' 'S. Africa' 'Samoa' 'Senegal' 'Serbia'
'Sierra Leone' 'Singapore' 'Slovakia' 'Slovenia' 'Solomon Is.' 'Somalia'
'Soviet Union' 'Spain' 'Sri Lanka' 'St. Lucia' 'Sudan' 'Suriname'
'Swaziland' 'Sweden' 'Switzerland' 'Syria' 'Taiwan' 'Tajikistan'
'Tanzania' 'Thailand' 'Timor-Leste' 'Togo' 'Trinidad-Tobago' 'Tunisia'
'Turk Cyprus' 'Turkey' 'Turkmenistan' 'UK' 'Uganda' 'Ukraine' 'Uruguay'
'Uzbekistan' 'Vanuatu' 'Venezuela' 'Vietnam' 'W. Samoa' 'Yemen'
'Yemen (AR)' 'Yemen (PDR)' 'Yugoslavia' 'Zaire (Democ Republic Congo)'
'Zambia' 'Zimbabwe']
Index([u'newid', u'newid2', u'country', u'year', u'cow', u'dateleg',
u'dateexec', u'legelec', u'exelec', u'seltrans', u'selrunoff', u'sp1',
u'sp2', u'sobsdom', u'siemass', u'sf1', u'sf2', u'sf3', u'sa1', u'sa2',
u'srec', u'sr0str', u'sr11cheat', u'sr13viol', u'sr12cap', u'sr21cheat',
u'sr23viol', u'sr22cap', u'intercoder', u'rec_score', u'problems'],
dtype='object')
In [885]:
import sys
seltrans_df = raw_df[['country','seltrans']]
seltrans_df = seltrans_df[seltrans_df.seltrans != ' ']
seltrans_df = seltrans_df[seltrans_df.seltrans == '1']
for c in seltrans_df.country.unique():
sys.stdout.write(c+', ')
Algeria, Argentina, Belarus, Benin, Bolivia, Brazil, Burkina Faso, Cambodia, Cent. Af. Rep., Chad, Congo, Cote d'Ivoire, El Salvador, Estonia, Ethiopia, Gabon, Georgia, Ghana, Guatemala, Guinea-Bissau, Honduras, Hungary, Indonesia, Madagascar, Mali, Moldova, Mongolia, Mozambique, Namibia, Nepal, Nicaragua, Niger, Nigeria, Pakistan, Paraguay, Peru, Philippines, Poland, ROK, Romania, Slovenia, Sudan, Suriname, Taiwan, Tajikistan, Turkey, Uruguay, Zambia, Zimbabwe,
In [872]:
field = 'sr22cap'
field2 = 'sa1'
sa2 = raw_df[['newid','year','country','cow',field,field2]]
sa2 = sa2[sa2.sr22cap != ' ']
In [873]:
# sa2 = sa2[sa2[field] != ' ']
sa2[field] = sa2[field].apply(lambda x:int(x))
# sa2 = sa2[sa2[field2] != ' ']
sa2[field] = sa2[field2].apply(lambda x:int(x))
sa2
Out[873]:
newid
year
country
cow
sr22cap
sa1
1
31
2004
Afghanistan
700
0
0.0
4
48
1991
Albania
339
0
0.0
5
49
1992
Albania
339
0
0.0
6
53
1996
Albania
339
1
1.0
7
54
1997
Albania
339
0
0.0
8
58
2001
Albania
339
0
0.0
12
75
1988
Algeria
615
0
0.5
14
82
1995
Algeria
615
0
0.0
15
84
1997
Algeria
615
0
0.5
16
86
1999
Algeria
615
1
1.0
17
89
2002
Algeria
615
0
0.0
18
91
2004
Algeria
615
0
0.0
19
97
1980
Angola
540
1
1.0
21
109
1992
Angola
540
0
0.0
22
130
1983
Argentina
160
0
0.0
23
132
1985
Argentina
160
0
0.0
24
134
1987
Argentina
160
0
0.0
25
136
1989
Argentina
160
0
0.0
26
138
1991
Argentina
160
0
0.0
27
140
1993
Argentina
160
0
0.0
28
142
1995
Argentina
160
0
0.0
29
144
1997
Argentina
160
0
0.0
30
146
1999
Argentina
160
0
0.0
31
148
2001
Argentina
160
0
0.0
32
150
2003
Argentina
160
0
0.0
34
157
1995
Armenia
371
1
1.0
35
158
1996
Armenia
371
1
1.0
36
160
1998
Armenia
371
1
1.0
37
161
1999
Armenia
371
1
1.0
38
165
2003
Armenia
371
1
1.0
...
...
...
...
...
...
...
1163
4802
1998
Venezuela
101
0
0.0
1164
4803
1998
Venezuela
101
0
0.0
1165
4805
2000
Venezuela
101
0
0.0
1167
4822
1987
Vietnam
818
1
1.0
1168
4827
1992
Vietnam
818
1
1.0
1169
4832
1997
Vietnam
818
1
1.0
1170
4833
1997
Vietnam
818
1
1.0
1171
4838
2002
Vietnam
818
1
1.0
1172
4839
2002
Vietnam
818
1
1.0
1177
4858
1991
W. Samoa
989
0
0.0
1178
4863
1996
W. Samoa
989
0
0.0
1179
4868
1993
Yemen
679
0
0.0
1180
4872
1997
Yemen
679
0
0.5
1181
4878
2003
Yemen
679
0
0.0
1183
4898
1978
Yemen (PDR)
680
0
0.5
1187
4921
1986
Yugoslavia
345
1
1.0
1191
4937
1984
Zaire (Democ Republic Congo)
490
1
1.0
1192
4940
1987
Zaire (Democ Republic Congo)
490
1
1.0
1193
4961
1978
Zambia
551
1
1.0
1195
4971
1988
Zambia
551
1
1.0
1196
4974
1991
Zambia
551
0
0.0
1197
4979
1996
Zambia
551
0
0.5
1198
4984
2001
Zambia
551
0
0.5
1199
4993
1980
Zimbabwe
552
0
0.0
1200
4998
1985
Zimbabwe
552
0
0.0
1201
5003
1990
Zimbabwe
552
0
0.0
1202
5008
1995
Zimbabwe
552
1
1.0
1203
5009
1996
Zimbabwe
552
1
1.0
1204
5013
2000
Zimbabwe
552
1
1.0
1205
5015
2002
Zimbabwe
552
1
1.0
981 rows × 6 columns
In [1027]:
adf = sa2[sa2['country'] == "Burundi"]
# adf = adf[~adf['newid'].isin([3750])]
# adf = adf.pivot(index='year',columns='country', values='sr22cap')
adf
Out[1027]:
newid
year
country
cow
sr22cap
sa1
163
689
1984
Burundi
516
1
1
164
698
1993
Burundi
516
0
0
In [866]:
adf.plot(ylim=[-1,5],xlim=[1994,2004],marker='o')
Out[866]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f619b577450>
In [340]:
countries_dict
Out[340]:
{'Afghanistan': {1988: '3', 2004: '2'},
'Albania': {1982: '3',
1987: '3',
1991: '2',
1992: '2',
1996: '3',
1997: '2',
2001: '2'},
'Algeria': {1982: '2',
1984: '2',
1987: '3',
1988: '3',
1991: '2',
1995: '2',
1997: '3',
1999: '3',
2002: '2',
2004: '2'},
'Angola': {1980: '3', 1986: '3', 1992: '2'},
'Argentina': {1983: '1',
1985: '1',
1987: '0',
1989: '0',
1991: '1',
1993: '1',
1995: '0',
1997: '0',
1999: '0',
2001: '1',
2003: '1'},
'Armenia': {1991: '0', 1995: '3', 1996: '2', 1998: '2', 1999: '2', 2003: '2'},
'Australia': {1977: '0',
1980: '0',
1983: '0',
1984: '0',
1987: '0',
1990: '0',
1993: '0',
1996: '0',
1998: '0',
2001: '0',
2004: '0'},
'Austria': {1979: '0',
1980: '0',
1983: '0',
1986: '0',
1990: '0',
1991: '0',
1992: '0',
1994: '0',
1995: '0',
1998: '0',
1999: '0',
2002: '0',
2004: '0'},
'Azerbaijan': {1992: '2',
1993: '3',
1995: '3',
1998: '2',
2000: '3',
2003: '3'},
'Bahamas': {1982: '1', 1987: '2', 1992: '0', 1997: '0', 2002: '0'},
'Bahrain': {2002: '2'},
'Bangladesh': {1978: '1',
1979: '1',
1981: '1',
1986: '2',
1988: '3',
1991: '1',
1996: '2',
2001: '2'},
'Barbados': {1981: '0',
1986: '0',
1991: '0',
1994: '0',
1999: '0',
2003: '0'},
'Belarus': {1994: '1', 1995: '2', 2000: '2', 2001: '3', 2004: '3'},
'Belgium': {1977: '0',
1978: '0',
1981: '0',
1985: '0',
1987: '0',
1991: '0',
1995: '0',
1999: '0',
2003: '0'},
'Belize': {1984: '0', 1989: '0', 1993: '1', 1998: '0', 2003: '0'},
'Benin': {1984: '2',
1989: '3',
1991: '0',
1995: '1',
1996: '0',
1999: '0',
2001: '1',
2003: '0'},
'Bolivia': {1978: '3',
1979: '1',
1980: '0',
1985: '0',
1989: '0',
1993: '1',
1997: '0',
2002: '1'},
'Bosnia-Herz': {1996: '3', 1997: '2', 1998: '2', 2000: '2', 2002: '1'},
'Botswana': {1979: '0',
1984: '1',
1989: '0',
1994: '0',
1999: '1',
2004: '1'},
'Brazil': {1982: '1',
1985: '0',
1986: '0',
1990: '0',
1994: '1',
1998: '0',
2002: '1'},
'Bulgaria': {1981: '2',
1986: '3',
1990: '2',
1991: '1',
1992: '1',
1994: '1',
1996: '1',
1997: '1',
2001: '1'},
'Burkina Faso': {1991: '2', 1992: '1', 1997: '2', 1998: '2', 2002: '2'},
'Burundi': {1982: '2', 1984: '2', 1993: ' '},
'C. Verde Is.': {1985: '2', 1991: '0', 1995: '0', 1996: '0', 2001: '0'},
'Cambodia': {1993: '2', 1998: '2', 2003: '2'},
'Cameroon': {1980: '3',
1983: '2',
1984: '3',
1988: '2',
1992: '2',
1997: '2',
2002: '2',
2004: '2'},
'Canada': {1979: '0',
1980: '0',
1984: '0',
1988: '0',
1993: '0',
1997: '0',
2000: '0',
2004: '0'},
'Cent. Af. Rep.': {1986: '3',
1987: '2',
1992: '3',
1993: '1',
1998: '2',
1999: '2'},
'Chad': {1990: '2', 1996: '2', 1997: '2', 2001: '3', 2002: '2'},
'Chile': {1989: '1', 1993: '1', 1997: '1', 1999: '1', 2001: '1'},
'Colombia': {1978: '1',
1982: '1',
1986: '1',
1990: '2',
1991: '2',
1994: '2',
1998: '2',
2002: '2'},
'Comoro Is.': {1978: '3',
1984: '2',
1987: '3',
1990: '1',
1992: '1',
1993: '1',
1996: '1',
2002: '0',
2004: '1'},
'Congo': {1979: '3', 1984: '3', 1989: '3', 1992: '1', 1993: '2', 2002: '2'},
'Costa Rica': {1978: '0',
1982: '1',
1986: '0',
1990: '0',
1994: '0',
1998: '0',
2002: '0'},
"Cote d'Ivoire": {1990: '2', 1995: '2', 2000: '3'},
'Croatia': {1992: '2', 1993: '2', 1995: '2', 1997: '3', 2000: '1', 2003: '1'},
'Cuba': {1981: '3', 1986: '3', 1993: '3', 1998: '3', 2003: '3'},
'Cyprus': {1981: '1',
1983: '0',
1985: '0',
1988: '0',
1991: '0',
1993: '0',
1996: '1',
1998: '0',
2001: '1',
2003: '0'},
'Czech Rep.': {1981: '2',
1986: '3',
1990: '0',
1992: '0',
1996: '1',
1998: '1',
2000: '0',
2002: '0',
2004: '0'},
'Denmark': {1977: '0',
1979: '0',
1981: '0',
1984: '0',
1987: '0',
1988: '0',
1990: '0',
1994: '0',
1998: '0',
2001: '0'},
'Djibouti': {1981: '2',
1982: '3',
1987: '3',
1992: '3',
1993: '3',
1997: '2',
1999: '2',
2003: '2'},
'Dom. Rep.': {1978: '2',
1982: '1',
1986: '0',
1990: '2',
1994: '2',
1996: '1',
1998: '1',
2000: '1',
2002: '1',
2004: '1'},
'Ecuador': {1979: '0',
1984: '2',
1986: '1',
1988: '0',
1990: '0',
1992: '1',
1994: '0',
1996: '0',
1998: '1',
2002: '0'},
'Egypt': {1979: '2',
1981: '2',
1984: '1',
1987: '2',
1990: '2',
1993: '3',
1995: '2',
2000: '3'},
'El Salvador': {1977: '3',
1978: '3',
1982: '2',
1984: '2',
1985: '2',
1988: '2',
1989: '2',
1991: '2',
1994: '2',
1997: '0',
1999: '0',
2000: '0',
2003: '1',
2004: '0'},
'Eq. Guinea': {1988: '2',
1989: '2',
1993: '3',
1996: '3',
1999: '2',
2002: '3',
2004: '3'},
'Estonia': {1992: '1',
1995: '0',
1996: '0',
1997: '0',
1999: '0',
2001: '0',
2003: '0'},
'Ethiopia': {1992: '3', 1994: '2', 1995: '2', 2000: '3'},
'FRG/Germany': {1980: '0',
1983: '0',
1987: '0',
1990: '0',
1994: '0',
1998: '0',
2002: '0'},
'Fiji': {1982: '1', 1987: '1', 1992: '2', 1994: '1', 1999: '1', 2001: '2'},
'Finland': {1978: '0',
1979: '0',
1982: '0',
1983: '0',
1987: '0',
1988: '0',
1991: '0',
1994: '0',
1995: '0',
1999: '0',
2000: '0',
2003: '0'},
'France': {1978: '0',
1981: '0',
1986: '0',
1988: '0',
1993: '0',
1995: '0',
1997: '0',
2002: '0'},
'GDR': {1981: '3', 1986: '3', 1990: '0'},
'Gabon': {1979: '2',
1980: '3',
1985: '2',
1986: '2',
1990: '2',
1993: '2',
1996: '2',
1998: '2',
2001: '2'},
'Gambia': {1977: '0',
1982: '1',
1987: '1',
1992: '0',
1996: '2',
1997: '2',
2001: '2',
2002: '1'},
'Georgia': {1992: '2', 1995: '2', 1999: '2', 2000: '3', 2003: '3', 2004: '2'},
'Ghana': {1979: '0', 1992: '2', 1996: '0', 2000: '1', 2004: '2'},
'Greece': {1977: '2',
1981: '0',
1985: '0',
1989: '0',
1990: '0',
1993: '1',
1996: '1',
2000: '1',
2004: '0'},
'Grenada': {1984: '1', 1990: '0', 1995: '0', 1999: '0', 2003: '0'},
'Guatemala': {1978: '2',
1982: '2',
1985: '1',
1990: '2',
1994: '2',
1995: '2',
1999: '1',
2003: '2'},
'Guinea': {1980: '3',
1982: '3',
1993: '3',
1995: '2',
1998: '3',
2002: '2',
2003: '2'},
'Guinea-Bissau': {1984: '2', 1989: '3', 1994: '1', 1999: '2', 2004: '0'},
'Guyana': {1980: '2', 1985: '2', 1992: '0', 1997: '1', 2001: '1'},
'Haiti': {1979: '3',
1984: '2',
1988: '3',
1990: '2',
1995: '3',
1997: '2',
2000: '3'},
'Honduras': {1980: '1',
1981: '0',
1985: '1',
1989: '2',
1993: '1',
1997: '0',
2001: '1'},
'Hungary': {1980: '2', 1985: '2', 1990: '0', 1994: '0', 1998: '1', 2002: '0'},
'Iceland': {1978: '0',
1979: '0',
1980: '0',
1983: '0',
1987: '0',
1988: '0',
1991: '0',
1995: '0',
1996: '0',
1999: '0',
2003: '0',
2004: '0'},
'India': {1977: '1',
1980: '0',
1984: '1',
1989: '1',
1991: '3',
1996: '1',
1998: '2',
1999: '2',
2004: '2'},
'Indonesia': {1977: '1',
1982: '2',
1987: '3',
1992: '2',
1997: '3',
1998: '3',
1999: '2',
2004: '1'},
'Iran': {1984: '3',
1988: '3',
1989: '2',
1992: '2',
1993: '3',
1996: '3',
1997: '2',
2000: '2',
2001: '3',
2004: ' '},
'Iraq': {1984: '3', 1989: '3', 1996: '3', 2000: '3'},
'Ireland': {1977: '0',
1981: '0',
1982: '0',
1983: '0',
1987: '1',
1989: '0',
1990: '0',
1992: '0',
1993: '0',
1997: '0',
2002: '0'},
'Israel': {1977: '0',
1981: '1',
1984: '1',
1988: '1',
1992: '2',
1996: '1',
1999: '1',
2001: '1',
2003: '2'},
'Italy': {1979: '0',
1983: '0',
1987: '0',
1992: '0',
1994: '0',
1996: '0',
2001: '0'},
'Jamaica': {1980: '2', 1983: '2', 1989: '1', 1993: '3', 1997: '2', 2002: '2'},
'Japan': {1979: '0',
1980: '0',
1983: '0',
1986: '0',
1989: '0',
1990: '0',
1992: '0',
1993: '0',
1995: '0',
1996: '0',
1998: '0',
2000: '0',
2001: '0',
2003: '0',
2004: '0'},
'Jordan': {1989: '2', 1993: '2', 1997: '2', 2003: '2'},
'Kazakhstan': {1994: '3', 1995: '2', 1999: '3', 2004: '3'},
'Kenya': {1979: '2', 1983: '2', 1988: '3', 1992: '3', 1997: '2', 2002: '2'},
'Kuwait': {1981: '2', 1985: '2', 1992: '2', 1996: '2', 1999: '2', 2003: '2'},
'Kyrgyzstan': {1995: '2', 2000: '3'},
'Laos': {1989: '3', 1992: '3', 1997: '2', 2002: '3'},
'Latvia': {1993: '1', 1995: '1', 1998: '0', 2002: '0'},
'Lebanon': {1992: '2', 1996: '3', 2000: '2', 2002: '2'},
'Lesotho': {1993: '0', 1998: '1', 2002: '0'},
'Liberia': {1985: '3', 1997: '2'},
'Lithuania': {1992: '0',
1993: '0',
1996: '0',
1997: '0',
2000: '0',
2002: '0',
2004: '1'},
'Luxembourg': {1979: '0',
1984: '0',
1989: '0',
1994: '0',
1999: '0',
2004: '0'},
'Macedonia': {1994: '2', 1998: '1', 1999: '2', 2002: '1', 2004: '1'},
'Madagascar': {1982: '2',
1983: '2',
1989: '3',
1992: '2',
1993: '1',
1996: '0',
1998: '1',
2001: '2',
2002: '2'},
'Malawi': {1978: '3',
1983: '3',
1987: '2',
1992: '3',
1994: '1',
1999: '1',
2004: '2'},
'Malaysia': {1978: '1',
1982: '2',
1986: '1',
1990: '1',
1995: '2',
1999: '2',
2004: '2'},
'Maldives': {1983: '2',
1984: '1',
1988: '2',
1989: '2',
1993: '2',
1994: '2',
1998: '2',
1999: '2'},
'Mali': {1979: '2',
1982: '2',
1985: '3',
1988: '3',
1992: '1',
1997: '1',
2002: '1'},
'Malta': {1981: '1', 1987: '1', 1992: '0', 1996: '0', 1998: '0', 2003: '0'},
'Mauritania': {1992: '3', 1996: '3', 1997: '2', 2001: '2', 2003: '2'},
'Mauritius': {1982: '0',
1983: '0',
1987: '0',
1991: '0',
1995: '0',
2000: '0'},
'Mexico': {1979: '1',
1982: '1',
1985: '2',
1988: '2',
1991: '2',
1994: '2',
1997: '1',
2000: '1',
2003: '0'},
'Moldova': {1994: '1', 1996: '1', 1998: '2', 2001: '1'},
'Mongolia': {1981: '2',
1986: '3',
1990: '2',
1992: '1',
1993: '0',
1996: '0',
1997: '0',
2000: '1',
2001: '0',
2004: '2'},
'Morocco': {1977: '1', 1984: '2', 1993: '2', 1997: '3', 2002: '2'},
'Mozambique': {1977: '3', 1986: '3', 1994: '2', 1999: '1', 2004: '2'},
'Myanmar': {1981: '3'},
'Namibia': {1989: '1', 1994: '0', 1999: '2', 2004: '1'},
'Nepal': {1981: '2', 1986: '2', 1991: '1', 1994: '1', 1999: '2'},
'Netherlands': {1977: '0',
1980: '0',
1981: '0',
1982: '0',
1986: '0',
1989: '0',
1994: '0',
1995: '0',
1998: '0',
1999: '0',
2002: '0',
2003: '0'},
'New Zealand': {1978: '0',
1981: '0',
1984: '0',
1987: '0',
1990: '1',
1993: '0',
1996: '0',
1999: '0',
2002: '0'},
'Nicaragua': {1984: '3', 1990: '2', 1996: '1', 2001: '1'},
'Niger': {1989: '2', 1993: '1', 1995: '1', 1996: '3', 1999: '2', 2004: '1'},
'Nigeria': {1979: '0',
1983: '3',
1992: '3',
1993: '3',
1998: '3',
1999: '2',
2003: '3'},
'Norway': {1977: '0',
1981: '0',
1985: '0',
1989: '0',
1993: '0',
1997: '0',
2001: '0'},
'P. N. Guinea': {1982: '0', 1987: '0', 1992: '1', 1997: '1', 2002: '2'},
'PRK': {1982: '3', 1986: '3', 1990: '3', 1998: '3', 2003: '3'},
'Pakistan': {1977: '2',
1985: '1',
1988: '2',
1990: '1',
1991: '1',
1993: '2',
1997: '1',
2002: '2'},
'Panama': {1978: '2',
1984: '3',
1989: '3',
1991: '0',
1994: '0',
1999: '1',
2004: '1'},
'Paraguay': {1978: '3',
1983: '3',
1988: '3',
1989: '2',
1993: '2',
1998: '1',
2000: '1',
2003: '1'},
'Peru': {1978: '1',
1980: '1',
1985: '0',
1990: '2',
1992: '2',
1995: '2',
2000: '3',
2001: '1'},
'Philippines': {1978: '3',
1981: '2',
1984: '2',
1986: '3',
1987: '2',
1992: '2',
1995: '2',
1998: '2',
2001: '2',
2004: '2'},
'Poland': {1980: '3',
1985: '2',
1989: '2',
1990: '0',
1991: '0',
1993: '0',
1995: '0',
1997: '0',
2000: '0',
2001: '0'},
'Portugal': {1979: '0',
1980: '0',
1983: '0',
1985: '0',
1986: '0',
1987: '0',
1991: '0',
1995: '0',
1996: '0',
1999: '0',
2001: '0',
2002: '0'},
'ROK': {1981: '2',
1985: '2',
1987: '2',
1988: '1',
1992: '1',
1996: '1',
1997: '0',
2000: '0',
2002: '0',
2004: '0'},
'Romania': {1980: '2',
1985: '3',
1990: '2',
1992: '1',
1996: '0',
2000: '0',
2004: '2'},
'Russia': {1993: '2',
1995: '1',
1996: '2',
1999: '2',
2000: '2',
2003: '2',
2004: '2'},
'Rwanda': {1978: '1', 1981: '2', 1983: '3', 1988: '2', 2003: '3'},
'S. Africa': {1981: '3',
1984: '3',
1987: '3',
1989: '3',
1994: '1',
1999: '1',
2004: '1'},
'Samoa': {2001: '1'},
'Senegal': {1978: '1',
1983: '1',
1988: '2',
1993: '2',
1998: '2',
2000: '1',
2001: '1'},
'Serbia': {1992: '3',
1996: '2',
1997: '3',
1998: '2',
2000: '2',
2001: '2',
2002: '1',
2003: '1',
2004: '1'},
'Sierra Leone': {1977: '2',
1982: '3',
1985: '3',
1986: '2',
1996: '1',
2002: '2'},
'Singapore': {1980: '2',
1984: '2',
1988: '2',
1991: '2',
1993: '2',
1997: '2',
1999: '2',
2001: '2'},
'Slovakia': {1994: '0', 1998: '2', 1999: '0', 2002: '1', 2004: '0'},
'Slovenia': {1992: '1',
1996: '0',
1997: '0',
2000: '0',
2002: '0',
2004: '0'},
'Solomon Is.': {1980: '0',
1984: '0',
1989: '0',
1993: '0',
1997: '0',
2001: '0'},
'Somalia': {1979: '2', 1984: '3', 1986: '3'},
'Soviet Union': {1979: '3', 1984: '3', 1989: '3'},
'Spain': {1977: '1',
1979: '0',
1982: '0',
1986: '0',
1989: '0',
1993: '0',
1996: '0',
2000: '1',
2004: '1'},
'Sri Lanka': {1977: '0',
1982: '2',
1988: '2',
1989: '2',
1994: '2',
1999: '2',
2000: '2',
2001: '2',
2004: '2'},
'St. Lucia': {1982: '1', 1987: '0', 1992: '0', 1997: '0', 2001: '0'},
'Sudan': {1977: '2',
1978: '2',
1980: '2',
1981: '2',
1982: '2',
1983: '3',
1986: '2',
1996: '3',
2000: '3'},
'Suriname': {1987: '1', 1991: '2', 1996: '1', 2000: '0'},
'Swaziland': {1978: '1',
1983: '2',
1987: '2',
1993: '2',
1998: '2',
2003: '2'},
'Sweden': {1979: '0',
1982: '0',
1985: '0',
1988: '0',
1991: '0',
1994: '0',
1998: '0',
2002: '0'},
'Switzerland': {1979: '0',
1983: '0',
1987: '0',
1991: '0',
1995: '0',
1999: '0',
2003: '0'},
'Syria': {1977: '2',
1978: '1',
1981: '3',
1985: '3',
1986: '3',
1990: '3',
1991: '3',
1994: '3',
1998: '3',
2000: '3',
2003: '2'},
'Taiwan': {1980: '3',
1983: '2',
1986: '2',
1989: '2',
1991: '2',
1995: '1',
1996: '1',
1998: '1',
2000: '1',
2001: '0',
2004: '2'},
'Tajikistan': {1994: '3', 1995: '3', 1999: '3', 2000: '3'},
'Tanzania': {1980: '2', 1985: '3', 1990: '3', 1995: '2', 2000: '1'},
'Thailand': {1979: '1',
1983: '1',
1986: '2',
1988: '1',
1992: '2',
1995: '0',
1996: '2',
2000: '1',
2001: '2'},
'Timor-Leste': {2001: '0', 2002: '0'},
'Togo': {1979: '2',
1985: '2',
1986: '3',
1990: '2',
1993: '3',
1994: '2',
1998: '3',
1999: '3',
2002: '2',
2003: '3'},
'Trinidad-Tobago': {1981: '0',
1986: '0',
1991: '0',
1995: '0',
2000: '0',
2001: '1',
2002: '0'},
'Tunisia': {1981: '2', 1986: '3', 1989: '2', 1994: '2', 1999: '2', 2004: '2'},
'Turk Cyprus': {1985: '0',
1990: '0',
1993: '0',
1995: '1',
1998: '0',
2000: '1',
2001: '0',
2003: '1'},
'Turkey': {1977: '0',
1979: '1',
1983: '2',
1987: '0',
1991: '1',
1995: '2',
1999: '2',
2002: '2'},
'Turkmenistan': {1992: '3', 1994: '3', 1999: '3'},
'UK': {1979: '0', 1983: '0', 1987: '1', 1992: '0', 1997: '1', 2001: '0'},
'Uganda': {1980: '1', 1989: '3', 1992: '3', 1996: '2', 2001: '3'},
'Ukraine': {1994: '1', 1998: '2', 1999: '2', 2002: '2', 2004: '2'},
'Uruguay': {1984: '1', 1989: '0', 1994: '0', 1999: '0', 2004: '0'},
'Uzbekistan': {1994: '2', 1999: '3', 2000: '3', 2004: '3'},
'Vanuatu': {1983: '0', 1987: '1', 1991: '1', 1995: '1', 1998: '0', 2002: '0'},
'Venezuela': {1978: '0',
1983: '1',
1988: '0',
1993: '2',
1998: '1',
2000: '2'},
'Vietnam': {1981: '3', 1987: '2', 1992: '2', 1997: '2', 2002: '3'},
'W. Samoa': {1979: '1',
1982: '1',
1985: '1',
1988: '1',
1991: '1',
1996: '2'},
'Yemen': {1993: '1', 1997: '1', 2003: '2'},
'Yemen (AR)': {1988: '2'},
'Yemen (PDR)': {1978: '3', 1986: '3'},
'Yugoslavia': {1978: '2', 1982: '2', 1986: '2'},
'Zaire (Democ Republic Congo)': {1977: '2', 1982: '3', 1984: '3', 1987: '2'},
'Zambia': {1978: '3', 1983: '3', 1988: '2', 1991: '1', 1996: '2', 2001: '2'},
'Zimbabwe': {1980: '1',
1985: '1',
1990: '2',
1995: '3',
1996: '2',
2000: '3',
2002: '3'}}
In [280]:
map(lambda x: x, countries_dict)
map(lambda x: countries_dict[x], countries_dict)
countries_dict['Canada']
Out[280]:
{1979: ' ',
1980: '0',
1984: '0',
1988: ' ',
1993: '0',
1997: '0',
2000: '0',
2004: '0'}
In [68]:
pd.date_range('1978', '2002', freq='365D\')
Out[68]:
DatetimeIndex(['1978-01-01', '1979-01-01', '1980-01-01', '1980-12-31',
'1981-12-31', '1982-12-31', '1983-12-31', '1984-12-30',
'1985-12-30', '1986-12-30', '1987-12-30', '1988-12-29',
'1989-12-29', '1990-12-29', '1991-12-29', '1992-12-28',
'1993-12-28', '1994-12-28', '1995-12-28', '1996-12-27',
'1997-12-27', '1998-12-27', '1999-12-27', '2000-12-26',
'2001-12-26'],
dtype='datetime64[ns]', freq='365D')
In [288]:
itu_mobile = pd.DataFrame.from_csv('Mobile_cellular_2000-2014.csv')
itu_mobile = itu_mobile[['2000','2001','2002','2003','2004','2005','2006','2007',
'2008','2009','2010','2011','2012','2013','2014']]
In [293]:
itu_mobile
Out[293]:
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
Afghanistan
0
0
25,000
200,000
600,000
1,200,000
2,520,366
4,668,096
7,898,909
10,500,000
13,000,000
17,558,265
19,520,813
21,588,228
23,423,741
Albania
29,791
392,650
851,000
1,100,000
1,259,590
1,530,244
1,909,885
2,322,436
1,859,632
2,463,741
2,692,372
3,100,000
3,500,000
3,685,983
3,359,654
Algeria
86,000
100,000
450,244
1,446,927
4,882,414
13,661,355
20,997,954
27,562,721
27,031,472
32,729,824
32,780,165
35,615,926
37,527,703
39,517,045
37,258,000
American Samoa
1,992
2,156
2,036
2,100
2,250
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Andorra
23,543
29,429
32,790
51,893
58,366
64,560
69,004
63,503
64,202
64,549
65,495
65,044
63,865
63,931
66,241
Angola
25,806
75,000
140,000
350,000
740,000
1,611,118
3,054,620
4,961,536
6,773,356
8,109,421
9,403,365
12,073,218
12,785,109
13,285,198
14,052,558
Anguilla
2,163
1,773
3,042
4,427
7,229
13,061
17,150
23,526
26,484
24,820
25,695
26,019
26,100
26,000
26,000
Antigua & Barbuda
22,000
25,000
38,205
46,100
54,000
86,000
110,177
112,381
136,592
134,925
167,970
176,008
127,381
114,358
109,100
Argentina
6,487,950
6,741,791
6,566,740
7,842,233
13,512,383
22,156,426
31,510,390
40,401,771
46,508,774
52,482,780
57,082,298
60,722,729
64,327,647
67,361,515
66,356,509
Armenia
17,486
25,504
71,349
114,379
203,309
318,044
1,259,762
1,876,411
1,442,000
2,191,500
3,865,354
3211215
3322837
3346275
3459137
Aruba
15,000
53,000
61,800
69,952
98,389
103,417
109,030
113,586
120,806
128,000
131,800
NaN
135,000
138,800
139,700
Ascension
0
0
NaN
0
0
0
0
0
0
0
0
0
0
NaN
0
Australia
8,562,000
11,132,000
12,670,000
14,347,000
16,480,000
18,420,000
19,760,000
21,260,000
22,120,000
22,200,000
22,500,000
23,789,000
24,338,000
24,940,000
31,010,000
Austria
6,117,000
6,541,000
6,736,000
7,274,000
7,992,000
8,665,000
9,281,000
9,912,000
10,816,000
11,434,000
12,241,000
13,022,578
13,588,000
13,272,000
12,952,605
Azerbaijan
420,400
730,000
794,200
1,057,100
1,456,523
2,242,000
3,323,500
4,519,000
6,548,000
7,757,120
9,100,113
10,120,105
10,125,200
10,130,102
10,552,520
Bahamas
31,524
60,555
121,759
122,228
186,007
227,771
252,987
373,999
358,050
358,812
428,377
298,790
300,000
287,000
273,300
Bahrain
205,727
299,587
388,990
443,109
649,764
767,103
907,433
1,115,979
1,440,782
1,401,974
1,567,000
1,693,650
2,123,903
2,210,190
2,328,994
Bangladesh
279,000
520,000
1,075,000
1,365,000
2,781,560
9,000,000
19,130,983
34,370,000
44,640,000
51,359,315
67,923,887
84,368,700
97,180,000
116,553,076
120,350,497
Barbados
28,467
53,111
97,193
140,000
200,138
206,190
237,119
257,596
288,662
337,061
350,061
347,917
349,296
307,708
305,456
Belarus
49,353
138,329
462,630
1,118,000
2,239,287
4,099,500
5,960,000
6,960,000
8,128,000
9,686,200
10,332,900
10,694,900
10,676,471
11,114,440
11,401,927
Belgium
5,629,000
7,697,000
8,101,777
8,605,834
9,131,705
9,604,695
9,847,375
10,738,121
11,341,704
11,775,240
12,154,041
12,495,934
12,313,375
12,315,217
12,734,724
Belize
16,812
39,155
51,729
60,403
75,000
96,000
118,000
118,314
160,032
161,783
194,201
222407
172423
174615
172300
Benin
55476
125000
218770
236,175
459,322
596,267
1,055,727
2,051,776
3,625,366
5,033,349
7,074,914
7,765,206
8,407,846
9,627,447
10,780,875
Bermuda
13,000
13,333
30,000
40,000
49,000
52,720
60,100
69,000
79,000
85,000
88,200
NaN
91,000
94,300
59,491
Bhutan
0
0
0
2,255
19,138
36,000
82,078
149,439
253,429
338,938
394,316
484,189
560,890
544,337
628,289
Bolivia
582,620
779,917
1,023,333
1,278,844
1,800,789
2,421,402
2,876,143
3,254,410
5,038,600
6,464,390
7,179,293
8,353,273
9,493,207
10,425,704
10,450,341
Bosnia and Herzegovina
93,386
444,711
748,780
1,074,790
1,407,441
1,594,367
1,887,820
2,450,425
3,179,036
3,257,239
3,110,233
3,171,283
3,357,541
3,488,319
3,491,188
Botswana
222190
332264
332,264
444978
522840
563782
823070
1,151,761
1,485,791
1,874,101
2,363,411
2900263
3081726
3246787
3410507
Brazil
23,188,171
28,745,769
34,880,964
46,373,266
65,605,000
86,210,336
99,918,621
120,980,103
150,641,403
169,385,584
196,929,978
234,357,507
248,323,703
271,099,799
280,728,796
British Virgin Islands
NaN
NaN
8,000
NaN
NaN
NaN
NaN
20,700
23,000
47,031
47,524
46,597
48,703
53,406
48,430
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Tajikistan
1,160
1,630
13,200
47,617
135,000
265,000
2,150,000
2,132,770
3,673,520
4,900,000
5,940,842
6,324,000
6,528,000
7,537,100
7,999,100
Tanzania
110518
275560
606,859
1,298,000
1,942,000
2964000
5609000
8252000
13006793
17469486
20983853
25666455
27219283
27442823
31862656
TFYR Macedonia
115748
223275
365346
776000
985600
1,131,006
1,263,841
1,794,433
1967531
1,943,216
2,153,425
2,213,223
2,235,460
2,237,250
2,300,305
Thailand
3,056,000
7,550,000
17,449,890
21,616,910
26,965,548
30,460,238
40,125,470
52,973,994
61,837,164
65,952,313
71,726,300
77,449,000
85,012,000
93,849,000
97,096,000
Timor-Leste
NaN
NaN
NaN
20,058
25,722
33,072
49,100
78,215
125,002
350,891
473,020
614,151
621,000
650,000
676,900
Togo
50,000
95,000
165,138
243,613
332,565
433,635
708,000
1,190,319
1,549,542
2,187,334
2,602,283
2,695,335
3,312,239
4,262,993
4,822,900
Tokelau
0
0
NaN
0
0
0
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Tonga
180
236
3,354
11,200
16,400
29,872
30,051
46,525
50,472
53,000
54,300
55,000
56,000
57,500
68,000
Trinidad & Tobago
161,860
256,106
262,772
336,352
651,189
924,100
1,518,800
1,509,800
1,806,120
1,846,345
1,894,240
1,826,200
1,883,683
1,943,873
1,980,566
Tunisia
119,165
389,208
574,334
1,917,530
3,735,695
5,680,726
7,339,047
7,842,619
8,602,164
9,797,026
11,114,206
12,387,656
12,843,889
12,712,365
14,283,633
Turkey
16133405
19572897
23,323,118
27,887,535
34,707,549
43,608,965
52,662,700
61,975,807
65,824,110
62,779,554
61,769,635
65321745
67680547
69661108
71888416
Turkmenistan
7,500
8,173
8,173
9,187
50,100
105,000
216,868
381,670
1,135,150
2,132,890
3,197,624
5,300,000
5,900,000
6,125,300
7,206,100
Turks & Caicos Is.
NaN
NaN
9,052
19,361
25,085
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Tuvalu
0
0
0
0
500
1,300
1600
1800
NaN
1000
1600
2130
2800
3400
3800
Uganda
126913
283520
393310
776169
1165035
1315300
2008818
4195278
8554864
9383734
12828264
16696992
16356387
18068648
20365941
Ukraine
818,524
2,224,600
3,692,700
6,498,423
13,735,000
30,013,500
49,076,239
55,240,400
55,681,476
54,942,815
53,928,830
55,576,481
59,343,693
62,458,800
61,170,229
United Arab Emirates
1,428,115
1,909,303
2,428,071
2,972,331
3,683,117
4,534,143
5,519,293
7,731,508
9,357,735
10,671,878
10,926,019
11,727,401
13,775,252
16,063,547
16,819,024
United Kingdom
43,452,000
46,283,000
49,228,000
54,256,221
59,687,915
65,471,665
70,077,926
73,836,210
74,940,937
76,481,053
76,729,827
77,162,298
78,329,355
78,673,978
78,460,684
United States
109,478,031
128,500,000
141,800,000
160,637,000
184,819,000
203,700,000
229,600,000
249,300,000
261,300,000
274,283,000
285,118,000
297,404,000
304,838,000
310,698,000
317,443,800
Uruguay
410,787
519,991
513,528
497,530
599,768
1,154,923
2,330,011
3,004,323
3,507,816
4,111,560
4,437,158
4,757,425
4,995,459
5,267,947
5,497,094
Uzbekistan
53,128
128,012
186,900
320,815
544,100
720,000
2,530,365
5,691,458
12,375,274
16,417,914
20,952,000
25,441,789
20,274,090
21,500,000
21,639,200
Vanuatu
365
350
4,900
7,800
10,504
12,692
15,000
26,000
36,000
131,682
169,935
136,956
146,084
127,244
156,051
Vatican
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Venezuela
5,447,172
6,472,584
6,541,894
7,015,121
8,420,980
12,495,721
18,789,466
23,820,133
27,414,377
28,123,570
27,880,132
28,781,999
30,569,073
30,896,079
30,528,022
Viet Nam
788,559
1,251,195
1,902,388
2,742,000
4,960,000
9,593,200
18,892,480
45,024,048
74,872,310
98,223,980
111,570,201
127,318,045
131,673,724
123,735,557
136,148,124
Virgin Islands (US)
35,000
41,000
45,150
49,300
64,200
80,300
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Wallis and Futuna
0
0
0
0
0
0
0
NaN
NaN
NaN
NaN
NaN
NaN
NaN
0
Yemen
32,042
147,837
486,667
675,162
1,476,000
2,277,559
2,977,781
4,349,000
6,445,000
8,313,000
11,085,000
11,668,000
13,900,000
16,844,700
17,100,000
Zambia
98,853
121,200
139,092
241,000
464,354
949,559
1,663,328
2,639,026
3,539,003
4,406,682
5,446,991
8,164,553
10,524,676
10,395,801
10,114,867
Zimbabwe
266,441
314,002
338,779
363,651
425,745
647,110
849,146
1,225,654
1,654,721
3,991,000
7,700,000
9,200,000
12,613,935
13,633,167
11,798,652
228 rows × 15 columns
In [290]:
m_stack = itu_mobile.stack()
In [ ]:
In [523]:
def get_country_series(country):
c1 = m_stack[country]
c1.index = c1.index.map(lambda x:int(x))
c1 = c1.map(lambda x: int(x.replace(',','')))
return c1
def plot_country(country):
s = get_country_series(country)
s.plot()
In [530]:
plot_country('Syria')
In [248]:
itu_tel = pd.DataFrame.from_csv('Fixed_tel_2000-2014.csv')
itu_tel = itu_tel[:228][['2000','2001','2002','2003','2004','2005','2006','2007',
'2008','2009','2010','2011','2012','2013','2014']]
In [250]:
t_stack = itu_tel.stack()
t_stack
Out[250]:
Afghanistan 2000 0.14
2001 0.14
2002 0.15
2003 0.16
2009 0.02
2010 0.06
2011 0.05
2012 0.30
2013 0.31
2014 0.33
Albania 2000 4.62
2001 6.01
2002 6.74
2003 7.87
2004 8.54
2005 8.73
2006 8.05
2007 9.48
2008 10.88
2009 11.52
2010 10.57
2011 10.74
2012 9.87
2013 8.86
2014 7.76
Algeria 2000 5.55
2001 5.85
2002 5.99
2003 6.30
2004 7.43
...
Zambia 2000 0.82
2001 0.83
2002 0.83
2003 0.81
2004 0.82
2005 0.83
2006 0.79
2007 0.76
2008 0.73
2009 0.70
2010 0.90
2011 0.63
2012 0.59
2013 0.80
2014 0.76
Zimbabwe 2000 1.99
2001 2.02
2002 2.28
2003 2.37
2004 2.50
2005 2.58
2006 2.64
2007 2.71
2008 2.72
2009 2.99
2010 2.90
2011 2.66
2012 2.20
2013 2.15
2014 2.26
dtype: float64
In [950]:
def get_country_series(country, stack):
c1 = stack[country]
c1.index = c1.index.map(lambda x:int(x))
c1 = c1.map(lambda x: int(x.replace(',','')))
return c1
def plot_country(country, stack):
s = get_country_series(country, stack)
s.plot(title=country)
In [894]:
plot_country('Congo (Dem. Rep.)', m_stack)
In [285]:
t_stack
Out[285]:
Afghanistan 2000 0.14
2001 0.14
2002 0.15
2003 0.16
2009 0.02
2010 0.06
2011 0.05
2012 0.30
2013 0.31
2014 0.33
Albania 2000 4.62
2001 6.01
2002 6.74
2003 7.87
2004 8.54
2005 8.73
2006 8.05
2007 9.48
2008 10.88
2009 11.52
2010 10.57
2011 10.74
2012 9.87
2013 8.86
2014 7.76
Algeria 2000 5.55
2001 5.85
2002 5.99
2003 6.30
2004 7.43
...
Zambia 2000 0.82
2001 0.83
2002 0.83
2003 0.81
2004 0.82
2005 0.83
2006 0.79
2007 0.76
2008 0.73
2009 0.70
2010 0.90
2011 0.63
2012 0.59
2013 0.80
2014 0.76
Zimbabwe 2000 1.99
2001 2.02
2002 2.28
2003 2.37
2004 2.50
2005 2.58
2006 2.64
2007 2.71
2008 2.72
2009 2.99
2010 2.90
2011 2.66
2012 2.20
2013 2.15
2014 2.26
dtype: float64
In [771]:
raw_df2 = pd.DataFrame.from_csv('31461-0002-Data.tsv',sep='\t', index_col=None)
raw_df2 = raw_df[raw_df['seltrans'] == '1']
# raw_df2[field] = raw_df2[field].filter(lambda x: x != ' ')
# raw_df2[field] = raw_df2[field].map(lambda x: int(x))
# raw_df2 = raw_df2[raw_df2[field] == '3' or raw_df2[field] == '2' ]
# raw_df2[raw_df2['country'].isin(raw_df2['country'].unique())]
# raw_df2[['country',field]].groupby('country').max()
# raw_df2['country'].unique()
i. SR0STR – legal framework ii. SR11CHEAT – pre-election cheating iii. SR13VIOL – pre-election violence iv. SR21CHEAT – election-day cheating v. SR23VIOL – election-day violence
In [781]:
aa_df = raw_df2[['newid','country','year','sr22cap','seltrans','sa1','sa2','sr0str','sr11cheat','sr21cheat','sr23viol','sr13viol']]
len(aa_df)
Out[781]:
73
In [782]:
field = 'sr22cap'
viol_df = aa_df[['newid','country','year',field]]
viol_df = viol_df[viol_df[field] != ' ']
In [783]:
viol_df[field] = map(lambda x:int(x), viol_df[field])
In [785]:
adf2 = viol_df[viol_df[field] >= 1].groupby('country').max()
len(adf2)
Out[785]:
14
In [962]:
itu_broad = pd.DataFrame.from_csv('Fixed_broadband_2000-2014_per100.csv')
itu_broad = itu_broad[['2000','2001','2002','2003','2004','2005','2006','2007',
'2008','2009','2010','2011','2012','2013','2014']]
itu_broad
Out[962]:
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
Country
Afghanistan
NaN
NaN
NaN
NaN
0.00
0.00
0.00
0.00
0.00
0.00
0.01
NaN
0.01
0.00
0.00
Albania
NaN
NaN
NaN
NaN
NaN
0.01
NaN
0.32
2.03
2.92
3.35
4.07
5.06
5.75
6.57
Algeria
NaN
NaN
NaN
0.05
0.11
0.40
0.49
0.82
1.36
2.25
2.43
2.60
3.00
3.26
4.01
American Samoa
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Andorra
NaN
NaN
1.60
4.76
7.95
12.73
17.85
22.79
25.85
29.17
31.45
33.09
34.34
35.01
35.89
Angola
NaN
NaN
NaN
NaN
NaN
NaN
0.04
0.07
0.09
0.11
0.10
0.11
0.17
0.35
0.41
Anguilla
NaN
10.81
11.90
13.71
11.80
17.55
22.00
25.10
27.33
27.65
27.52
28.28
29.01
30.07
30.43
Antigua & Barbuda
NaN
NaN
NaN
NaN
2.03
7.03
1.85
2.68
5.84
18.56
8.16
6.81
14.67
17.39
15.07
Argentina
NaN
0.25
0.39
0.68
1.42
2.40
4.06
6.61
7.85
8.77
9.98
11.23
12.53
14.57
14.69
Armenia
NaN
0.00
0.00
0.00
0.03
0.07
NaN
0.13
0.46
1.34
3.16
5.42
7.14
8.17
9.13
Aruba
NaN
NaN
NaN
1.44
7.05
12.27
13.84
15.80
18.15
18.54
18.91
NaN
NaN
18.66
18.56
Ascension
NaN
NaN
NaN
NaN
4.38
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Australia
NaN
0.63
1.31
2.59
5.01
9.82
18.69
NaN
24.56
23.69
24.59
24.41
24.88
25.00
25.76
Austria
2.38
3.98
5.57
7.38
10.62
14.25
17.30
19.52
20.73
22.44
24.40
24.88
25.17
26.26
27.54
Azerbaijan
NaN
NaN
0.01
NaN
NaN
0.03
0.05
0.17
0.68
1.11
5.23
10.58
14.71
18.19
19.83
Bahamas
NaN
1.37
2.44
3.47
3.97
4.07
4.94
5.99
7.32
8.91
6.85
4.23
NaN
4.11
3.61
Bahrain
NaN
0.17
0.68
1.26
1.82
2.44
4.06
6.61
8.39
11.71
12.38
22.55
22.41
22.52
21.39
Bangladesh
NaN
NaN
NaN
NaN
NaN
NaN
NaN
0.03
0.03
0.21
0.27
0.31
0.39
0.97
1.19
Barbados
NaN
NaN
NaN
10.09
10.89
11.68
14.11
17.06
17.73
20.54
20.04
22.23
23.62
23.82
26.97
Belarus
NaN
NaN
0.00
0.00
0.01
0.02
0.12
1.77
5.00
11.47
17.56
22.20
26.92
29.77
28.84
Belgium
1.40
4.47
7.89
11.97
15.52
19.13
23.15
25.56
27.69
29.03
30.83
32.20
33.38
34.48
35.99
Belize
NaN
NaN
NaN
0.36
1.07
1.85
2.60
2.61
2.74
2.77
2.89
3.07
3.08
2.98
2.91
Benin
NaN
NaN
0.00
0.00
0.00
0.00
0.02
0.01
0.09
0.21
0.28
0.38
0.42
0.41
0.40
Bermuda
NaN
NaN
NaN
NaN
NaN
28.82
36.75
44.64
52.51
61.72
61.74
NaN
NaN
61.37
53.06
Bhutan
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
0.30
0.48
1.21
1.81
2.26
2.72
3.26
Bolivia
NaN
NaN
0.04
0.06
0.09
0.14
0.18
0.35
0.81
0.96
0.94
0.71
1.11
1.44
1.59
Bosnia and Herzegovina
0.00
0.00
0.01
0.04
0.17
0.35
1.03
2.19
4.88
7.58
10.16
11.21
12.24
13.48
14.15
Botswana
NaN
NaN
NaN
NaN
NaN
0.09
0.09
0.18
0.46
0.51
0.61
0.96
1.11
1.07
1.63
Brazil
0.06
0.19
0.41
0.53
1.72
1.74
2.53
4.01
5.22
6.06
7.22
9.06
9.62
10.66
11.46
British Virgin Islands
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
28.97
25.27
26.33
26.47
21.81
22.38
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Tajikistan
NaN
NaN
NaN
0.00
NaN
NaN
NaN
0.05
0.05
0.06
0.06
0.06
0.07
0.07
0.07
Tanzania
NaN
NaN
NaN
NaN
NaN
0.01
0.01
0.01
0.02
0.02
0.02
0.06
0.09
0.11
0.17
TFYR Macedonia
NaN
NaN
NaN
NaN
NaN
0.60
1.74
4.79
8.62
11.08
12.31
13.38
14.83
16.06
16.19
Thailand
NaN
0.00
NaN
0.02
0.25
0.85
1.36
1.96
3.13
3.96
4.90
5.85
6.77
7.75
8.21
Timor-Leste
NaN
NaN
NaN
0.00
0.00
0.00
0.00
0.00
0.01
0.04
0.05
0.05
0.05
0.06
0.07
Togo
NaN
NaN
NaN
NaN
NaN
NaN
NaN
0.02
0.03
0.07
0.43
0.53
0.62
0.10
0.11
Tokelau
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Tonga
NaN
NaN
0.01
0.02
0.33
0.64
0.62
0.76
0.70
0.97
1.06
1.24
1.43
1.61
1.70
Trinidad & Tobago
NaN
NaN
0.01
0.07
0.33
0.83
1.58
2.71
6.49
9.83
12.26
12.93
15.06
15.84
17.47
Tunisia
NaN
NaN
0.00
0.00
0.03
0.17
0.43
0.93
2.19
3.55
4.54
5.20
4.86
4.86
4.44
Turkey
NaN
0.02
0.03
0.30
0.86
2.35
4.04
6.84
8.18
9.05
9.84
10.39
10.63
11.87
11.69
Turkmenistan
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
0.00
0.01
0.01
0.02
0.03
0.03
0.04
Turks & Caicos Is.
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Tuvalu
NaN
NaN
NaN
NaN
0.52
1.55
2.57
2.77
2.96
1.02
2.44
4.57
5.58
7.09
9.10
Uganda
NaN
NaN
NaN
NaN
NaN
0.00
0.00
0.01
0.02
0.02
0.04
0.10
0.11
0.27
0.29
Ukraine
NaN
NaN
NaN
NaN
NaN
0.28
1.11
1.71
3.44
4.12
6.42
6.92
8.01
8.83
8.42
United Arab Emirates
0.07
0.27
0.52
0.90
1.53
3.12
4.94
6.55
8.20
8.95
9.32
9.71
10.37
11.15
11.51
United Kingdom
0.09
0.56
2.28
5.22
10.21
16.42
21.47
40.65
28.22
28.97
30.86
32.98
34.54
36.49
37.38
United States
2.48
4.45
6.85
9.47
12.64
17.16
20.02
23.60
25.15
25.85
27.07
28.04
29.14
30.00
30.37
Uruguay
NaN
NaN
NaN
NaN
0.81
1.46
3.20
4.94
7.30
9.45
11.37
13.98
17.10
21.63
24.58
Uzbekistan
NaN
NaN
NaN
0.01
0.02
0.03
0.03
0.07
0.24
0.32
0.42
0.52
0.77
1.06
1.33
Vanuatu
NaN
NaN
NaN
0.01
0.01
0.03
0.04
0.06
0.09
0.22
0.21
0.14
0.13
0.12
1.77
Vatican
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
Venezuela
0.02
0.15
0.31
0.45
0.80
1.33
1.98
3.10
3.97
4.90
5.76
6.15
6.80
7.35
7.82
Viet Nam
NaN
NaN
0.00
0.01
0.06
0.25
0.60
1.50
2.35
3.64
4.12
4.27
5.26
5.62
6.48
Virgin Islands (US)
NaN
NaN
NaN
NaN
1.37
2.75
NaN
5.54
6.94
8.45
8.55
NaN
NaN
8.53
8.52
Wallis and Futuna
NaN
NaN
NaN
NaN
NaN
NaN
NaN
1.61
4.99
6.42
7.82
8.40
8.81
9.53
10.42
Yemen
NaN
NaN
NaN
NaN
NaN
0.01
0.01
0.05
0.12
0.24
0.37
0.47
0.70
1.05
1.36
Zambia
0.00
0.00
0.00
0.00
0.00
0.00
0.02
0.03
0.05
0.08
0.08
0.12
0.11
0.10
0.14
Zimbabwe
NaN
0.01
0.02
0.05
0.07
0.08
0.08
0.12
0.14
0.37
0.25
0.25
0.52
0.73
1.04
228 rows × 15 columns
In [963]:
b_stack = itu_broad.stack()
In [902]:
def get_country_series_b(country, stack):
c1 = stack[country]
c1.index = c1.index.map(lambda x:int(x))
# c1 = c1.map(lambda x: int(x.replace(',','')))
return c1
def plot_country_b(country, stack):
s = get_country_series_b(country, stack)
s.plot(title=country,xlim=[1999,2015])
In [927]:
for c in seltrans_df.country.unique():
try:
if(is_above(c,5)):
plot_country_b(c, b_stack)
except:
continue
In [943]:
def is_above(country, base, stack):
cstack = stack[country]
return cstack.max() >= base
In [944]:
is_above("Algeria", 5, b_stack)
Out[944]:
False
In [951]:
for c in seltrans_df.country.unique():
try:
# if(is_above(c,0.5*(10**8))):
if(is_above(c,0.9*(10**8), m_stack)):
plot_country(c, m_stack)
except:
continue
In [952]:
is_above("Afghanistan", 1000000000000, m_stack)
m_stack["Afghanistan"].max()
Out[952]:
'7,898,909'
In [990]:
ldc = ["Angola",
"Madagascar",
"Benin",
"Malawi",
"Burkina Faso",
"Mali",
"Burundi",
"Mauritania",
"Central African Rep.",
"Mozambique",
"Chad",
"Niger",
"Comoros",
"Rwanda",
"Congo (Dem. Rep.)",
"S. Tome & Principe",
"Djibouti",
"Senegal",
"Equatorial Guinea",
"Sierra Leone",
"Eritrea",
"Somalia",
"Ethiopia",
"South Sudan",
"Gambia",
"Sudan",
"Guinea",
"Togo",
"Guinea-Bissau",
"Uganda",
"Lesotho",
"Tanzania",
"Liberia",
"Zambia",
"Afghanistan",
"Nepal",
"Bangladesh",
"Solomon Islands",
"Bhutan",
"Timor-Leste",
"Cambodia",
"Tuvalu",
"Kiribati",
"Vanuatu",
"Lao P.D.R.",
"Yemen",
"Myanmar",
"Haiti"]
In [1013]:
v = 0
for c in ldc:
try:
str_val = m_stack[c]["2014"]
str_val = str_val.replace(',','')
v += int(str_val)
except:
print c
S. Tome & Principe
In [1017]:
m_stack["Comoros"]["2014"]
Out[1017]:
'383,000'
In [1018]:
v2 = v+383000
In [1021]:
v2/float(932000000)
Out[1021]:
0.6227034763948498
In [ ]:
In [ ]:
Content source: rahulsmehta/election-fidelity
Similar notebooks: