In [98]:
import pandas as pd
import numpy as np
itu_mobile = pd.DataFrame.from_csv('mobile_cell_2.csv')
itu_mobile = itu_mobile[['2000','2001','2002','2003','2004','2005','2006','2007',
'2008','2009','2010','2011','2012','2013','2014']]
In [99]:
pop_df = pd.DataFrame.from_csv('sp.pop.totl_Indicator_en_csv_v2.csv')
In [100]:
ldc = ["Angola",
"Madagascar",
"Benin",
"Malawi",
"Burkina Faso",
"Mali",
"Burundi",
"Mauritania",
"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 [101]:
ldc_pop = ["Angola",
"Madagascar",
"Benin",
"Malawi",
"Burkina Faso",
"Mali",
"Burundi",
"Mauritania",
"Mozambique",
"Chad",
"Niger",
"Comoros",
"Rwanda",
"Congo, Dem. Rep.",
"Sao Tome and Principe",
"Djibouti",
"Senegal",
"Equatorial Guinea",
"Sierra Leone",
"Eritrea",
"Somalia",
"Ethiopia",
"South Sudan",
"Gambia, The",
"Sudan",
"Guinea",
"Togo",
"Guinea-Bissau",
"Uganda",
"Lesotho",
"Tanzania",
"Liberia",
"Zambia",
"Afghanistan",
"Nepal",
"Bangladesh",
"Solomon Islands",
"Bhutan",
"Timor-Leste",
"Cambodia",
"Tuvalu",
"Kiribati",
"Vanuatu",
"Lao PDR",
"Yemen, Rep.",
"Myanmar",
"Haiti"]
In [102]:
ldc_pop_df = pop_df[pop_df.index.isin(ldc_pop)]
In [103]:
def ldc_pop_by_year(year):
return ldc_pop_df[year].sum()
In [104]:
ldc_pop_by_year("2000")
Out[104]:
In [105]:
m_stack = itu_mobile.stack()
In [106]:
for k,v in m_stack.iteritems():
m_stack[k] = int(v.replace(',',''))
In [107]:
def ldc_total_phone_by_year(year):
val = 0
for c in ldc:
try:
# print c
val += m_stack[c][year]
except:
print c
return val
def prevalence_year(year):
return ldc_total_phone_by_year(year)/ldc_pop_by_year(year)
In [162]:
prevalence_year("2006")
Out[162]:
In [114]:
pop_stack = pop_df.stack()
In [163]:
m_stack["Haiti"]["2006"]/pop_stack["Haiti"]["2006"]
Out[163]:
In [145]:
for p in itu_mobile.index:
if "Cote" in p:
print p
In [ ]: