In [1]:
%matplotlib inline
import pickle
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')

pd.set_option('display.max_columns', 25)

In [2]:
with open ('un_explore.pkl', 'r') as picklefile:
    undata = pickle.load(picklefile)

Explore HIV incidence variable and reshape dataframes for possible visualizations

Explore HIV incidence

Group by country/year and unstack to investigate by year

Add a mean HIV incidence column sort by this column to find the 20 countries with the highest average rate over this time period.


In [3]:
hiv = 'hiv_incidence_rate_1549_years_old_percentage_midpoint'
yearly = pd.DataFrame(undata.groupby(['countryname', 'iso3code', 'year'])[hiv].mean())
hivdf = yearly.unstack()

In [4]:
hivdf['mean'] = hivdf.mean(axis=1, skipna=True)

In [5]:
hivdf = hivdf.sort(columns='mean', ascending=False)
hivdf.head(20)


Out[5]:
hiv_incidence_rate_1549_years_old_percentage_midpoint mean
year 1990.0 1991.0 1992.0 1993.0 1994.0 1995.0 1996.0 1997.0 1998.0 1999.0 2000.0 2001.0 2002.0 2003.0 2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0
countryname iso3code
Swaziland SWZ 0.78 1.39 2.18 3.06 3.86 4.50 4.91 5.05 4.96 4.74 4.42 4.12 3.83 3.66 3.59 3.49 3.39 3.27 3.22 3.12 3.11 2.89 2.41 2.18 3.422083
Zimbabwe ZWE 4.25 5.06 5.65 5.95 5.92 5.59 5.05 4.40 3.73 3.13 2.63 2.24 1.97 1.77 1.65 1.56 1.49 1.44 1.41 1.37 1.30 1.21 1.10 0.97 2.951667
Botswana BWA 1.92 2.69 3.59 4.45 5.13 5.52 5.53 5.29 4.89 4.37 3.83 3.33 2.89 2.47 2.13 1.86 1.70 1.57 1.51 1.35 1.20 1.15 1.06 0.93 2.931667
Lesotho LSO 0.44 0.87 1.56 2.49 3.53 4.36 4.73 4.62 4.26 3.84 3.43 3.13 2.91 2.78 2.73 2.73 2.70 2.75 2.82 2.65 2.38 2.28 2.30 2.21 2.854167
South Africa ZAF 0.16 0.33 0.59 0.97 1.46 1.99 2.48 2.83 3.01 3.04 2.95 2.78 2.59 2.40 2.24 2.11 2.01 1.93 1.88 1.84 1.79 1.69 1.52 1.36 1.914583
Namibia NAM 0.50 0.79 1.16 1.59 2.06 2.49 2.83 3.01 3.03 2.95 2.72 2.45 2.19 1.92 1.68 1.47 1.22 1.08 0.99 0.95 0.91 0.93 0.96 0.91 1.699583
Malawi MWI 2.32 2.30 2.29 2.32 2.35 2.40 2.43 2.43 2.41 2.36 2.27 2.14 1.98 1.80 1.61 1.41 1.21 1.03 0.86 0.73 0.63 0.55 0.47 0.40 1.695833
Zambia ZMB 2.18 2.06 2.01 1.99 1.99 1.99 1.97 1.96 1.92 1.87 1.81 1.80 1.73 1.64 1.52 1.43 1.34 1.24 1.11 1.04 1.02 0.98 0.78 0.70 1.586667
Mozambique MOZ NaN 0.37 0.47 0.58 0.71 0.87 1.05 1.25 1.44 1.63 1.75 1.81 1.80 1.72 1.63 1.50 1.38 1.26 1.16 1.11 1.07 1.00 1.00 0.98 1.197391
Kenya KEN 1.15 1.69 2.24 2.60 2.59 2.24 1.75 1.33 1.02 0.82 0.77 0.70 0.65 0.61 0.58 0.55 0.54 0.55 0.56 0.52 0.51 0.51 0.44 0.43 1.056250
Uganda UGA 1.95 1.60 1.34 1.09 0.89 0.73 0.59 0.58 0.53 0.53 0.56 0.61 0.62 0.66 0.71 0.75 0.79 0.86 0.89 0.89 0.90 0.93 0.87 0.79 0.860833
United Republic of Tanzania TZA 1.34 1.45 1.48 1.45 1.37 1.26 1.13 1.02 0.90 0.83 0.75 0.71 0.66 0.62 0.59 0.55 0.52 0.48 0.44 0.41 0.38 0.34 0.33 0.27 0.803333
Central African Republic CAF 0.97 1.11 1.25 1.36 1.42 1.46 1.39 1.34 1.24 1.07 0.96 0.79 0.65 0.52 0.45 0.36 0.31 0.29 0.26 0.26 0.26 0.28 0.28 0.26 0.772500
Cameroon CMR 0.40 0.48 0.57 0.66 0.74 0.80 0.84 0.83 0.83 0.81 0.78 0.75 0.71 0.67 0.61 0.57 0.51 0.49 0.46 0.42 0.40 0.39 0.36 0.34 0.600833
Cote d'Ivoire CIV 0.82 0.90 0.95 1.01 1.03 1.03 1.03 0.99 0.89 0.81 0.71 0.59 0.48 0.40 0.31 0.24 0.17 0.14 0.11 0.12 0.14 0.14 0.14 0.14 0.553750
Gabon GAB 0.25 0.33 0.42 0.52 0.63 0.73 0.82 0.89 0.92 0.94 0.91 0.84 0.75 0.65 0.52 0.42 0.33 0.27 0.23 0.22 0.21 0.19 0.19 0.17 0.514583
Congo COG 0.90 0.91 0.91 0.87 0.83 0.78 0.69 0.66 0.60 0.53 0.47 0.43 0.40 0.35 0.31 0.29 0.27 0.24 0.23 0.20 0.17 0.15 0.14 0.13 0.477500
Guinea-Bissau GNB 0.20 0.26 0.32 0.38 0.44 0.48 0.52 0.55 0.57 0.55 0.54 0.54 0.52 0.51 0.49 0.46 0.45 0.43 0.40 0.38 0.37 0.36 0.32 0.31 0.431250
Nigeria NGA 0.25 0.30 0.35 0.40 0.44 0.48 0.53 0.53 0.51 0.52 0.54 0.50 0.46 0.46 0.42 0.41 0.37 0.37 0.34 0.31 0.29 0.28 0.23 0.20 0.395417
Rwanda RWA 0.93 0.88 0.81 0.74 0.67 0.60 0.54 0.48 0.42 0.37 0.33 0.29 0.26 0.24 0.23 0.21 0.19 0.17 0.16 0.15 0.14 0.13 0.12 0.10 0.381667

Investigate percent change from previous year in countries with highest HIV incidence


In [6]:
hiv_change = hivdf.pct_change(axis=1)

In [7]:
highest = hiv_change.head(20)
highest


Out[7]:
hiv_incidence_rate_1549_years_old_percentage_midpoint mean
year 1990.0 1991.0 1992.0 1993.0 1994.0 1995.0 1996.0 1997.0 1998.0 1999.0 2000.0 2001.0 2002.0 2003.0 2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0
countryname iso3code
Swaziland SWZ NaN 0.782051 0.568345 0.403670 0.261438 0.165803 0.091111 0.028513 -0.017822 -0.044355 -0.067511 -0.067873 -0.070388 -0.044386 -0.019126 -0.027855 -0.028653 -0.035398 -0.015291 -0.031056 -0.003205 -0.070740 -0.166090 -0.095436 0.569763
Zimbabwe ZWE NaN 0.190588 0.116601 0.053097 -0.005042 -0.055743 -0.096601 -0.128713 -0.152273 -0.160858 -0.159744 -0.148289 -0.120536 -0.101523 -0.067797 -0.054545 -0.044872 -0.033557 -0.020833 -0.028369 -0.051095 -0.069231 -0.090909 -0.118182 2.042955
Botswana BWA NaN 0.401042 0.334572 0.239554 0.152809 0.076023 0.001812 -0.043400 -0.075614 -0.106339 -0.123570 -0.130548 -0.132132 -0.145329 -0.137652 -0.126761 -0.086022 -0.076471 -0.038217 -0.105960 -0.111111 -0.041667 -0.078261 -0.122642 2.152330
Lesotho LSO NaN 0.977273 0.793103 0.596154 0.417671 0.235127 0.084862 -0.023256 -0.077922 -0.098592 -0.106771 -0.087464 -0.070288 -0.044674 -0.017986 0.000000 -0.010989 0.018519 0.025455 -0.060284 -0.101887 -0.042017 0.008772 -0.039130 0.291478
South Africa ZAF NaN 1.062500 0.787879 0.644068 0.505155 0.363014 0.246231 0.141129 0.063604 0.009967 -0.029605 -0.057627 -0.068345 -0.073359 -0.066667 -0.058036 -0.047393 -0.039801 -0.025907 -0.021277 -0.027174 -0.055866 -0.100592 -0.105263 0.407782
Namibia NAM NaN 0.580000 0.468354 0.370690 0.295597 0.208738 0.136546 0.063604 0.006645 -0.026403 -0.077966 -0.099265 -0.106122 -0.123288 -0.125000 -0.125000 -0.170068 -0.114754 -0.083333 -0.040404 -0.042105 0.021978 0.032258 -0.052083 0.867674
Malawi MWI NaN -0.008621 -0.004348 0.013100 0.012931 0.021277 0.012500 0.000000 -0.008230 -0.020747 -0.038136 -0.057269 -0.074766 -0.090909 -0.105556 -0.124224 -0.141844 -0.148760 -0.165049 -0.151163 -0.136986 -0.126984 -0.145455 -0.148936 3.239583
Zambia ZMB NaN -0.055046 -0.024272 -0.009950 0.000000 0.000000 -0.010050 -0.005076 -0.020408 -0.026042 -0.032086 -0.005525 -0.038889 -0.052023 -0.073171 -0.059211 -0.062937 -0.074627 -0.104839 -0.063063 -0.019231 -0.039216 -0.204082 -0.102564 1.266667
Mozambique MOZ NaN -0.830275 0.270270 0.234043 0.224138 0.225352 0.206897 0.190476 0.152000 0.131944 0.073620 0.034286 -0.005525 -0.044444 -0.052326 -0.079755 -0.080000 -0.086957 -0.079365 -0.043103 -0.036036 -0.065421 0.000000 -0.020000 0.221828
Kenya KEN NaN 0.469565 0.325444 0.160714 -0.003846 -0.135135 -0.218750 -0.240000 -0.233083 -0.196078 -0.060976 -0.090909 -0.071429 -0.061538 -0.049180 -0.051724 -0.018182 0.018519 0.018182 -0.071429 -0.019231 0.000000 -0.137255 -0.022727 1.456395
Uganda UGA NaN -0.179487 -0.162500 -0.186567 -0.183486 -0.179775 -0.191781 -0.016949 -0.086207 0.000000 0.056604 0.089286 0.016393 0.064516 0.075758 0.056338 0.053333 0.088608 0.034884 0.000000 0.011236 0.033333 -0.064516 -0.091954 0.089662
United Republic of Tanzania TZA NaN 0.082090 0.020690 -0.020270 -0.055172 -0.080292 -0.103175 -0.097345 -0.117647 -0.077778 -0.096386 -0.053333 -0.070423 -0.060606 -0.048387 -0.067797 -0.054545 -0.076923 -0.083333 -0.068182 -0.073171 -0.105263 -0.029412 -0.181818 1.975309
Central African Republic CAF NaN 0.144330 0.126126 0.088000 0.044118 0.028169 -0.047945 -0.035971 -0.074627 -0.137097 -0.102804 -0.177083 -0.177215 -0.200000 -0.134615 -0.200000 -0.138889 -0.064516 -0.103448 0.000000 0.000000 0.076923 0.000000 -0.071429 1.971154
Cameroon CMR NaN 0.200000 0.187500 0.157895 0.121212 0.081081 0.050000 -0.011905 0.000000 -0.024096 -0.037037 -0.038462 -0.053333 -0.056338 -0.089552 -0.065574 -0.105263 -0.039216 -0.061224 -0.086957 -0.047619 -0.025000 -0.076923 -0.055556 0.767157
Cote d'Ivoire CIV NaN 0.097561 0.055556 0.063158 0.019802 0.000000 0.000000 -0.038835 -0.101010 -0.089888 -0.123457 -0.169014 -0.186441 -0.166667 -0.225000 -0.225806 -0.291667 -0.176471 -0.214286 0.090909 0.166667 0.000000 0.000000 0.000000 2.955357
Gabon GAB NaN 0.320000 0.272727 0.238095 0.211538 0.158730 0.123288 0.085366 0.033708 0.021739 -0.031915 -0.076923 -0.107143 -0.133333 -0.200000 -0.192308 -0.214286 -0.181818 -0.148148 -0.043478 -0.045455 -0.095238 0.000000 -0.105263 2.026961
Congo COG NaN 0.011111 0.000000 -0.043956 -0.045977 -0.060241 -0.115385 -0.043478 -0.090909 -0.116667 -0.113208 -0.085106 -0.069767 -0.125000 -0.114286 -0.064516 -0.068966 -0.111111 -0.041667 -0.130435 -0.150000 -0.117647 -0.066667 -0.071429 2.673077
Guinea-Bissau GNB NaN 0.300000 0.230769 0.187500 0.157895 0.090909 0.083333 0.057692 0.036364 -0.035088 -0.018182 0.000000 -0.037037 -0.019231 -0.039216 -0.061224 -0.021739 -0.044444 -0.069767 -0.050000 -0.026316 -0.027027 -0.111111 -0.031250 0.391129
Nigeria NGA NaN 0.200000 0.166667 0.142857 0.100000 0.090909 0.104167 0.000000 -0.037736 0.019608 0.038462 -0.074074 -0.080000 0.000000 -0.086957 -0.023810 -0.097561 0.000000 -0.081081 -0.088235 -0.064516 -0.034483 -0.178571 -0.130435 0.977083
Rwanda RWA NaN -0.053763 -0.079545 -0.086420 -0.094595 -0.104478 -0.100000 -0.111111 -0.125000 -0.119048 -0.108108 -0.121212 -0.103448 -0.076923 -0.041667 -0.086957 -0.095238 -0.105263 -0.058824 -0.062500 -0.066667 -0.071429 -0.076923 -0.166667 2.816667

Save to CSV for possible visualization


In [8]:
highest.to_csv('hiv_pctchange.csv')

Investigate ODA received by countries with highest HIV incidence rate

ODA = Official Development Assistence


In [9]:
oda_mill = 'net_oda_mill'
oda_pc = 'net_oda_received_per_capita_current_us'
oda_pct = 'net_oda_received__of_gni'

Create function to unstack

Create a list of the countries with the highest average HIV incidence from 1990 to 2013.

The subset_unstack function takes a column and dataframe, creates a temporary dataframe for each country, and concatenates the dataframes for each country together. Then unstacks to expand the dataframe by year.


In [10]:
highest_countries = []

for i in range(20):
    highest_countries.append(highest.index[i][0])

In [11]:
def subset_unstack(col, df):
    temp2_df = df
    ## find only the countries with highest HIV incidence
    for country in highest_countries:
        country_df = undata[undata['countryname'] == country]
        temp1_df = country_df[['countryname', 'iso3code', 'year', col]]
        temp2_df = pd.concat([temp2_df, temp1_df])
        
    ## unstack dataframe
    yearly = pd.DataFrame(temp2_df.groupby(['countryname', 'iso3code', 'year'])[col].mean())
    new_df = yearly.unstack()
    return new_df

ODA in millions US dollars


In [12]:
temp = highest_countries[-1]
oda1_df = undata[undata['countryname'] == temp]
oda1_df = oda1_df[['countryname', 'iso3code', 'year', oda_mill]]

oda1b_df = subset_unstack(oda_mill, oda1_df)
oda1b_df


Out[12]:
net_oda_mill
year 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
countryname iso3code
Botswana BWA 145.22 131.07 111.26 129.90 85.18 89.54 74.45 121.50 106.25 60.89 30.62 29.17 37.19 27.85 50.18 47.98 68.81 107.67 720.26 279.16 156.14 120.15 73.86 108.38
Cameroon CMR 444.38 516.26 714.78 543.72 730.08 442.80 410.19 498.77 497.31 434.29 376.73 457.76 605.85 885.98 790.66 413.93 1718.93 1926.29 548.59 648.34 540.50 611.84 596.24 737.49
Central African Republic CAF 248.89 173.44 177.65 171.74 167.56 167.78 168.63 91.00 119.95 118.09 75.28 76.39 60.24 51.25 109.83 88.90 133.66 176.92 257.28 242.03 261.01 268.76 227.25 189.25
Congo COG 217.16 133.27 112.89 122.36 361.85 124.86 429.29 268.59 64.91 140.35 32.04 73.78 57.66 69.15 115.48 1425.48 258.30 118.71 485.00 283.28 1311.50 259.79 138.60 150.42
Cote d'Ivoire CIV 686.40 629.90 755.70 763.03 1593.10 1211.84 964.17 446.32 967.08 447.36 350.57 185.91 1067.72 253.67 160.52 91.21 247.14 171.08 625.67 2401.60 844.96 1436.00 2635.63 1262.00
Gabon GAB 131.23 142.71 68.31 100.66 180.83 143.54 126.31 38.83 44.56 47.61 11.66 8.53 71.66 -10.57 39.87 60.43 29.05 51.14 62.05 77.21 104.00 72.55 73.20 90.87
Guinea-Bissau GNB 126.35 112.82 107.30 94.53 174.36 117.60 180.77 124.35 95.83 52.42 81.07 60.70 60.04 150.44 76.39 66.03 87.02 122.32 133.78 146.55 125.39 119.68 78.87 103.62
Kenya KEN 1181.29 916.46 883.14 914.39 676.63 731.85 595.02 448.60 415.21 310.47 512.72 471.23 392.81 523.00 660.24 759.20 946.70 1326.78 1365.96 1776.20 1628.57 2482.42 2654.08 3236.28
Lesotho LSO 139.13 123.31 143.16 143.06 115.62 112.65 103.21 91.34 61.17 31.02 36.67 55.12 76.80 78.87 98.04 67.49 70.62 128.79 143.80 122.39 256.23 264.71 282.68 320.00
Malawi MWI 500.36 549.57 577.04 496.34 470.14 434.14 491.54 343.94 434.52 446.62 446.11 409.43 378.14 518.13 505.61 573.35 722.80 743.95 923.63 771.39 1022.85 799.64 1174.60 1125.88
Mozambique MOZ 997.51 1065.10 1459.68 1175.53 1198.94 1062.39 885.73 947.14 1039.80 818.52 906.22 960.72 2219.27 1047.97 1242.86 1297.15 1639.30 1776.55 1996.38 2012.40 1951.53 2084.98 2096.92 2314.14
Namibia NAM 119.62 180.45 142.34 152.55 137.10 190.37 185.92 165.16 180.83 178.55 152.33 112.13 142.42 146.17 173.11 125.13 151.73 217.42 210.16 325.53 256.44 290.60 264.86 261.72
Nigeria NGA 255.08 258.32 258.82 288.42 189.66 210.96 188.75 199.75 203.15 151.80 173.70 176.17 297.93 308.22 576.94 6408.81 11428.02 1956.26 1290.16 1657.07 2061.96 1768.55 1915.82 2529.48
Rwanda RWA 287.92 359.16 348.93 353.91 711.75 694.70 465.31 229.67 350.07 373.08 321.46 304.88 362.92 335.24 490.11 577.40 603.07 722.57 933.51 933.59 1032.20 1264.00 878.99 1081.11
South Africa ZAF NaN NaN NaN 270.45 293.08 386.17 362.34 495.59 512.98 540.44 486.37 425.35 511.24 655.68 629.09 690.20 714.99 807.49 1125.18 1074.54 1030.54 1403.15 1067.15 1292.95
Swaziland SWZ 53.63 52.92 56.01 54.21 57.78 57.75 33.05 28.28 34.80 28.99 13.13 29.15 22.30 40.09 24.89 46.65 34.78 50.67 69.89 56.03 91.45 124.90 88.15 115.93
Uganda UGA 663.10 663.28 723.72 609.19 751.17 833.16 673.69 813.05 655.38 605.03 853.28 822.19 725.39 997.65 1216.02 1192.16 1586.43 1737.30 1641.47 1784.70 1723.47 1577.82 1655.19 1692.56
United Republic of Tanzania TZA 1163.15 1073.00 1334.08 944.43 963.57 871.05 867.21 943.85 1001.42 991.86 1063.92 1274.23 1269.84 1725.39 1772.41 1499.07 1883.29 2821.59 2331.46 2933.14 2958.18 2445.77 2831.89 3430.28
Zambia ZMB 474.81 877.97 1030.78 866.92 715.13 2030.67 608.06 609.51 347.97 623.03 794.65 570.84 811.33 774.54 1130.47 1172.05 1467.54 1007.84 1116.24 1267.06 914.37 1035.06 957.72 1142.42
Zimbabwe ZWE 334.26 388.68 788.78 496.05 558.98 489.10 369.36 335.51 261.21 244.50 175.64 160.93 198.83 186.97 187.05 372.72 278.24 478.11 612.42 736.22 732.47 715.68 1001.22 811.05

ODA per capita


In [13]:
oda2_df = undata[undata['countryname'] == temp]
oda2_df = oda2_df[['countryname', 'iso3code', 'year', oda_pc]]

oda2b_df = subset_unstack(oda_pc, oda2_df)
oda2b_df


Out[13]:
net_oda_received_per_capita_current_us
year 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
countryname iso3code
Botswana BWA 104.934418 92.010392 75.941660 86.294919 55.137504 56.547305 45.928751 73.309846 62.790016 35.300106 17.443566 16.356866 20.558592 15.196971 27.055020 25.578352 36.293266 56.219053 372.473974 143.033179 79.285406 60.477143 36.857943 53.623097
Cameroon CMR 36.815806 41.532254 55.856016 41.287099 53.892582 31.788479 28.650657 33.908189 32.917196 27.994051 23.652485 27.996800 36.101085 51.440849 44.733340 22.821484 92.356319 100.865152 27.996391 32.249392 26.206895 28.920029 27.476965 33.139721
Central African Republic CAF 85.446289 58.209390 58.230838 54.954268 52.352144 51.219665 50.332821 26.571414 34.289651 33.082852 20.690891 20.623400 15.990452 13.382473 28.207864 22.444411 33.148963 43.078753 61.475145 56.731361 60.003389 60.583150 50.218675 40.994997
Congo COG 91.118008 54.462162 44.943525 47.455345 136.659747 45.893731 153.450921 93.314429 21.919005 46.100372 10.248851 23.015714 17.559359 20.559443 33.483450 402.352106 70.832075 31.581401 125.113666 70.906044 318.966660 61.483533 31.957199 33.820244
Cote d'Ivoire CIV 56.653268 50.271036 58.350729 57.047424 115.451550 85.236221 65.892854 29.671292 62.649038 28.309896 21.732241 11.322049 64.031234 15.001359 9.362865 5.243764 13.992422 9.531418 34.264430 129.108964 44.526445 74.058969 132.845928 62.118264
Gabon GAB 138.617919 146.739617 68.390496 98.151350 171.765586 132.848733 113.926425 34.138905 38.198924 39.810388 9.514274 6.795194 55.752740 -8.033014 29.596363 43.806838 20.560447 35.332613 41.845293 50.824307 66.828512 45.513458 44.837226 54.357482
Guinea-Bissau GNB 124.190940 108.406032 100.780414 86.785680 156.482079 103.188037 155.105473 104.349183 78.656463 42.086501 63.668606 46.629609 45.114059 110.572199 54.925578 46.450442 59.903942 82.407162 88.191862 94.493215 79.029436 73.684236 47.410430 60.800760
Kenya KEN 50.382491 37.812348 35.273478 35.387799 25.404117 26.692244 21.110313 15.499083 13.979078 10.186493 16.388658 14.668021 11.903144 15.425448 18.953566 21.215167 25.755289 35.144345 35.229418 44.600423 39.809389 59.066014 61.468140 72.965292
Lesotho LSO 87.090478 75.747896 86.222265 84.477983 67.021502 64.231074 58.009315 50.697155 33.580203 16.862261 19.755148 29.452311 40.732182 41.537701 51.275561 35.044375 36.394314 65.850830 72.913535 61.506438 127.546081 130.430112 137.788837 154.256640
Malawi MWI 52.964273 56.905926 59.126380 50.643657 47.721534 43.570571 48.411775 33.057616 40.608663 40.554970 39.403803 35.225342 31.705126 42.335244 40.226457 44.360640 54.315093 54.248442 65.328652 52.931593 68.127804 51.731418 73.844105 68.808274
Mozambique MOZ 73.519532 76.661494 101.716607 78.930558 77.583900 66.475943 53.799859 55.995320 59.928283 45.989173 49.586285 51.140976 114.869678 52.732136 60.808773 61.738543 75.938108 80.127988 87.704681 86.143480 81.424810 84.819530 83.199902 89.578161
Namibia NAM 84.510406 123.077280 94.035168 97.821069 85.376516 115.081846 109.024230 93.949324 99.921590 96.141990 80.260154 58.059879 72.726233 73.777140 86.411557 61.730831 73.908962 104.493680 99.564571 151.868581 117.688795 131.041505 117.226175 113.627532
Nigeria NGA 2.667717 2.633624 2.572962 2.796265 1.793428 1.945680 1.697908 1.752508 1.738295 1.266775 1.413612 1.398119 2.305520 2.325309 4.242229 45.913021 79.740622 13.290952 8.532348 10.664559 12.910830 10.771171 11.347374 14.569449
Rwanda RWA 39.907433 51.502338 53.311638 58.340647 124.247966 122.655344 78.472740 35.494236 48.826597 47.507868 38.289209 34.803641 40.380425 36.733932 52.959793 61.233643 62.423494 72.779975 91.315031 88.662814 95.250118 113.421058 76.715419 91.802147
South Africa ZAF NaN NaN NaN 7.217043 7.655573 9.871421 9.058444 12.109398 12.243052 12.590776 11.053864 9.471220 11.224611 14.214659 13.462894 14.576861 14.898201 16.595725 22.802667 21.466885 20.289492 27.217368 20.388144 24.323007
Swaziland SWZ 62.163277 59.645105 61.688623 58.527959 61.193172 59.942206 33.570136 28.090111 33.829302 27.658229 12.343532 27.122309 20.606496 36.849831 22.735618 42.230877 31.102085 44.644076 60.566985 47.738818 76.645982 103.039288 71.609321 92.780073
Uganda UGA 37.816144 36.532085 38.519430 31.352318 37.406718 40.170243 31.469528 36.815369 28.769404 25.737415 35.149638 32.772199 27.960439 37.172445 43.793734 41.502713 53.394662 56.536637 51.652990 54.305081 50.709365 44.890666 45.539987 45.040198
United Republic of Tanzania TZA 45.640906 40.740539 48.982051 33.541505 33.149584 29.089007 28.174049 29.881873 30.928708 29.890523 31.272898 36.515703 35.463955 46.935555 46.932437 38.611559 47.150209 68.618946 55.047258 67.212573 65.776317 52.762177 59.265506 69.645935
Zambia ZMB 60.527635 109.224213 125.254573 102.922240 82.909038 229.679037 67.016330 65.397444 36.332093 63.321340 78.670577 55.089023 76.357431 71.094465 101.163795 102.183762 124.561902 83.226394 89.610852 98.795863 69.181436 75.918695 68.043571 78.578189
Zimbabwe ZWE 31.950580 36.213385 71.829599 44.247503 48.910392 42.021196 31.179856 27.852832 21.359009 19.742058 14.047096 12.785654 15.729074 14.753293 14.736414 29.323582 21.866808 37.527786 47.905040 57.120388 56.012177 53.573923 72.952264 57.319447

ODA as percentage of GNI (gross national income)


In [14]:
oda3_df = undata[undata['countryname'] == temp]
oda3_df = oda3_df[['countryname', 'year', oda_pct]]

oda3b_df = subset_unstack(oda_pct, oda3_df)
oda3b_df


Out[14]:
net_oda_received__of_gni
year 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
countryname iso3code
Botswana BWA 3.941052 3.272047 2.612443 2.916636 2.111078 1.905848 1.620354 2.492079 2.163927 1.166028 0.563267 0.544977 0.784489 0.409810 0.627415 0.527505 0.735623 1.055492 6.983930 2.783507 1.275942 0.771658 0.498536 0.728692
Cameroon CMR 4.163320 4.427735 6.648723 4.247124 8.417524 5.396513 4.487030 5.402998 5.428941 4.334770 4.333259 5.121921 5.935662 6.765157 5.143284 2.571123 9.710903 9.664587 2.394579 2.786467 2.313934 2.327791 2.290883 2.547626
Central African Republic CAF 17.548801 12.741169 12.721746 13.629466 20.178761 15.330877 17.090080 9.869815 12.644845 11.912229 8.351119 8.267226 6.132488 4.507607 8.742579 6.633935 9.223720 10.488054 13.109881 12.249073 13.078948 12.186924 10.418660 12.207044
Congo COG 9.344875 5.847937 4.417661 7.916224 23.892303 10.165336 29.502715 16.168992 4.389937 8.532177 1.408215 3.749541 2.653163 2.682102 3.652486 35.351638 5.059348 2.055837 5.531419 4.059131 14.533132 2.424894 1.314758 1.361280
Cote d'Ivoire CIV 7.453448 6.905650 7.705520 7.883311 21.130249 12.103072 8.590802 4.056422 8.045046 3.809723 3.608517 1.875651 9.880192 1.948645 1.087305 0.555047 1.446001 0.875745 2.682163 10.288401 3.524749 5.886860 10.068062 4.223325
Gabon GAB 2.459172 2.942942 1.404292 2.687475 4.896820 3.343249 2.561550 0.842240 1.122898 1.162900 0.271850 0.194318 1.483145 -0.182740 0.607302 0.710833 0.330315 0.474665 0.454260 0.692949 0.814020 0.465039 0.476442 0.608394
Guinea-Bissau GNB 54.152635 46.978863 50.419734 42.661635 78.707159 49.841815 71.785478 48.985463 49.818696 24.944487 22.659609 16.126969 14.748110 32.326152 14.667058 11.476296 14.843658 17.681558 15.727397 17.967953 14.811451 10.851186 8.234039 10.957691
Kenya KEN 14.394403 11.782833 11.243549 16.959481 9.971231 8.386840 5.034028 3.465811 2.973412 2.440197 4.077109 3.670442 3.015548 3.548543 4.138463 4.053022 3.675728 4.170426 3.808776 4.803545 4.086542 5.916100 5.280407 5.924814
Lesotho LSO 15.366048 12.530459 12.999280 13.577585 10.663223 9.416239 9.081276 7.717994 5.648042 2.861925 3.614808 5.126883 7.646998 5.379089 5.459223 3.610244 3.772167 6.360815 7.082784 5.805666 9.877622 8.472925 9.878758 11.177310
Malawi MWI 27.230924 25.478211 32.776356 24.464040 41.291189 32.157038 21.923793 13.117376 25.423372 25.753882 26.131757 24.322205 14.428460 21.741236 19.602801 21.116487 23.475257 20.512126 21.709995 15.515435 19.335110 14.506415 28.616028 30.253134
Mozambique MOZ 42.153748 41.078048 81.290337 63.227911 60.897529 51.357774 28.846150 26.105472 25.303936 18.929035 22.235916 25.479034 55.092130 23.452112 23.022378 20.858954 25.329415 20.639316 19.218717 19.242911 19.844165 15.971140 14.038942 14.857198
Namibia NAM 4.209219 5.803335 4.107771 4.658816 3.717559 4.643885 4.627869 3.961536 4.619977 4.696689 3.864420 3.162453 4.194966 2.832642 2.587485 1.750347 1.914115 2.534520 2.524887 3.738328 2.365566 2.406287 2.119051 2.037311
Nigeria NGA 0.915264 1.035903 0.982185 2.145556 1.205479 0.801326 0.576211 0.594739 0.696240 NaN 0.431682 0.439954 0.561926 0.513733 0.739785 6.481326 8.117241 1.265345 0.668788 1.069640 0.590164 0.454907 0.436658 0.513599
Rwanda RWA 11.343267 18.897168 17.284268 18.090559 94.946034 53.480621 34.004276 12.515679 17.769297 20.654569 18.697642 18.460456 21.883783 18.465978 23.843437 22.605440 19.569581 19.226348 19.605382 17.703522 18.249577 19.910454 12.336286 14.634387
South Africa ZAF NaN NaN NaN 0.205435 0.213412 0.253084 0.250761 0.331799 0.381082 0.405056 0.365175 0.361144 0.453657 0.384231 0.280490 0.272990 0.268286 0.278784 0.404992 0.371416 0.280537 0.345649 0.276015 0.362732
Swaziland SWZ 4.569225 4.316857 4.094175 3.858014 4.118989 3.245246 1.905078 1.524687 2.130006 1.772435 0.842369 2.008027 1.816716 2.212381 1.027134 1.688770 1.174235 1.637205 2.318400 1.825605 2.769848 3.517205 2.548186 3.658063
Uganda UGA 15.685768 20.324011 26.122758 19.208025 19.116949 14.622617 11.230459 13.002968 9.965762 10.109844 14.021317 14.526869 12.000708 16.077617 15.740073 13.627281 16.363794 14.409358 11.741081 10.685573 9.329992 8.601690 7.109757 7.039984
United Republic of Tanzania TZA 28.562533 22.489392 30.221686 23.070880 22.115207 16.993606 13.499059 12.480968 10.837667 10.328813 10.519282 12.414321 11.870763 14.956367 13.944823 10.834362 10.216432 13.604326 8.872094 10.734988 9.879824 7.596304 7.589574 8.010578
Zambia ZMB 15.784197 29.335056 35.948780 28.720137 20.907739 56.961568 17.930415 15.040382 10.496701 19.227083 23.070010 14.527056 20.065827 16.275943 19.415802 15.221159 12.663973 8.054708 6.760067 8.498264 4.837289 4.584692 3.892247 4.450818
Zimbabwe ZWE 3.927011 4.661839 12.189280 7.854095 8.476233 7.208261 4.485711 4.129572 4.341223 3.759963 2.775202 2.496073 3.274361 3.394693 3.387329 6.800695 5.422667 9.699197 15.417136 8.543809 7.906713 7.121761 8.696128 6.502967

Explore precent change by region


In [15]:
byregion = undata.groupby(['year', 'mdgregions'])[hiv].mean()
byregion = byregion.unstack()
byregion.to_csv('hiv_byregion.csv')
byregion


Out[15]:
mdgregions Caribbean Caucasus and Central Asia Developed Eastern Asia Latin America Northern Africa Oceania South-eastern Asia Southern Asia Sub-Saharan Africa Western Asia
year
1990 0.250000 0.001220 0.005650 NaN 0.050175 0.001825 0.010 0.110600 0.002620 0.619250 NaN
1991 0.256000 0.000660 0.010667 NaN 0.059583 0.002275 0.020 0.130940 0.002840 0.719024 NaN
1992 0.252000 0.002600 0.014300 NaN 0.060000 0.002600 0.030 0.131400 0.005180 0.839024 NaN
1993 0.236000 0.002840 0.024667 NaN 0.065833 0.003025 0.040 0.149980 0.009780 0.958293 NaN
1994 0.238000 0.003520 0.031867 NaN 0.075833 0.003425 0.050 0.150320 0.012700 1.058293 NaN
1995 0.234000 0.006400 0.042533 NaN 0.085000 0.003850 0.060 0.136500 0.016840 1.121220 NaN
1996 0.224000 0.009880 0.053333 NaN 0.093333 0.004150 0.070 0.114720 0.021120 1.139268 NaN
1997 0.222000 0.012540 0.063333 NaN 0.104167 0.004350 0.080 0.089080 0.025520 1.120488 NaN
1998 0.210000 0.013360 0.066667 NaN 0.107500 0.004750 0.090 0.083620 0.027960 1.067805 NaN
1999 0.190000 0.014320 0.060000 NaN 0.100833 0.005025 0.100 0.076000 0.028540 1.004146 NaN
2000 0.180000 0.015060 0.060000 NaN 0.081667 0.005300 0.120 0.068000 0.026580 0.930976 NaN
2001 0.164000 0.015340 0.060000 NaN 0.065000 0.005425 0.150 0.060000 0.024680 0.857561 NaN
2002 0.148000 0.015740 0.060000 NaN 0.055000 0.005450 0.170 0.056000 0.022760 0.784878 NaN
2003 0.138000 0.014000 0.063333 NaN 0.050000 0.005725 0.150 0.050000 0.020800 0.719512 NaN
2004 0.124000 0.014000 0.060000 NaN 0.046667 0.005850 0.120 0.046000 0.016940 0.663171 NaN
2005 0.112000 0.016000 0.063333 NaN 0.045833 0.005975 0.070 0.042000 0.013100 0.613415 NaN
2006 0.104000 0.020000 0.056667 NaN 0.045000 0.006300 0.040 0.036000 0.011280 0.567317 NaN
2007 0.098000 0.020000 0.053333 NaN 0.043333 0.006475 0.020 0.032000 0.009480 0.531861 NaN
2008 0.094000 0.020000 0.050000 NaN 0.041667 0.006525 0.010 0.030000 0.009720 0.506254 NaN
2009 0.090000 0.020000 0.046667 NaN 0.041667 0.006825 0.020 0.028000 0.009880 0.477363 NaN
2010 0.086000 0.022000 0.050000 NaN 0.037500 0.007100 0.030 0.026000 0.009860 0.453883 NaN
2011 0.084000 0.026000 0.050000 NaN 0.037500 0.007375 0.040 0.026000 0.010160 0.432398 NaN
2012 0.072000 0.024000 0.046667 NaN 0.037500 0.007525 0.040 0.024000 0.010340 0.395159 NaN
2013 0.078571 0.021117 0.016181 0.0072 0.033684 0.007825 0.025 0.023943 0.007522 0.341362 0.0043

In [16]:
byregion = byregion.transpose()
byregion


Out[16]:
year 1990.0 1991.0 1992.0 1993.0 1994.0 1995.0 1996.0 1997.0 1998.0 1999.0 2000.0 2001.0 2002.0 2003.0 2004.0 2005.0 2006.0 2007.0 2008.0 2009.0 2010.0 2011.0 2012.0 2013.0
mdgregions
Caribbean 0.250000 0.256000 0.252000 0.236000 0.238000 0.234000 0.224000 0.222000 0.210000 0.190000 0.180000 0.164000 0.148000 0.138000 0.124000 0.112000 0.104000 0.098000 0.094000 0.090000 0.086000 0.084000 0.072000 0.078571
Caucasus and Central Asia 0.001220 0.000660 0.002600 0.002840 0.003520 0.006400 0.009880 0.012540 0.013360 0.014320 0.015060 0.015340 0.015740 0.014000 0.014000 0.016000 0.020000 0.020000 0.020000 0.020000 0.022000 0.026000 0.024000 0.021117
Developed 0.005650 0.010667 0.014300 0.024667 0.031867 0.042533 0.053333 0.063333 0.066667 0.060000 0.060000 0.060000 0.060000 0.063333 0.060000 0.063333 0.056667 0.053333 0.050000 0.046667 0.050000 0.050000 0.046667 0.016181
Eastern Asia NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.007200
Latin America 0.050175 0.059583 0.060000 0.065833 0.075833 0.085000 0.093333 0.104167 0.107500 0.100833 0.081667 0.065000 0.055000 0.050000 0.046667 0.045833 0.045000 0.043333 0.041667 0.041667 0.037500 0.037500 0.037500 0.033684
Northern Africa 0.001825 0.002275 0.002600 0.003025 0.003425 0.003850 0.004150 0.004350 0.004750 0.005025 0.005300 0.005425 0.005450 0.005725 0.005850 0.005975 0.006300 0.006475 0.006525 0.006825 0.007100 0.007375 0.007525 0.007825
Oceania 0.010000 0.020000 0.030000 0.040000 0.050000 0.060000 0.070000 0.080000 0.090000 0.100000 0.120000 0.150000 0.170000 0.150000 0.120000 0.070000 0.040000 0.020000 0.010000 0.020000 0.030000 0.040000 0.040000 0.025000
South-eastern Asia 0.110600 0.130940 0.131400 0.149980 0.150320 0.136500 0.114720 0.089080 0.083620 0.076000 0.068000 0.060000 0.056000 0.050000 0.046000 0.042000 0.036000 0.032000 0.030000 0.028000 0.026000 0.026000 0.024000 0.023943
Southern Asia 0.002620 0.002840 0.005180 0.009780 0.012700 0.016840 0.021120 0.025520 0.027960 0.028540 0.026580 0.024680 0.022760 0.020800 0.016940 0.013100 0.011280 0.009480 0.009720 0.009880 0.009860 0.010160 0.010340 0.007522
Sub-Saharan Africa 0.619250 0.719024 0.839024 0.958293 1.058293 1.121220 1.139268 1.120488 1.067805 1.004146 0.930976 0.857561 0.784878 0.719512 0.663171 0.613415 0.567317 0.531861 0.506254 0.477363 0.453883 0.432398 0.395159 0.341362
Western Asia NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.004300

Find percent change in sub-Saharan Africa from peak in 1996 to low in 2013


In [17]:
print 'max: %f \nmin: %f' % (byregion.ix[9].max(), byregion.ix[9].min())


max: 1.139268 
min: 0.341362

In [18]:
ssafrica = byregion.ix[9]
change = ssafrica[[1996, 2013]]
change.pct_change()


Out[18]:
year
1996         NaN
2013   -0.700367
Name: Sub-Saharan Africa, dtype: float64

Find percent change worldwide from peak in 1996 to low in 2013


In [19]:
# worldwide yearly mean of HIV incidence rate
world_means = undata.groupby(['year'])[hiv].mean()
print 'max: %f \nmin: %f' % (world_means.max(), world_means.min())


max: 0.616360 
min: 0.147564

In [20]:
world_change = world_means[[1996, 2013]]
world_change.pct_change()


Out[20]:
year
1996         NaN
2013   -0.760588
Name: hiv_incidence_rate_1549_years_old_percentage_midpoint, dtype: float64

In [ ]: