Build total donator type visualization for Benin

This commit is contained in:
Marty Oehme 2022-09-06 12:17:20 +02:00
parent dd56a77c66
commit d43cf791b6
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 201 additions and 0 deletions

View file

@ -100,3 +100,25 @@ The primary reasons for not having access to electricity are the lack of physica
as well as connection costs to the main electrical grid being too high. as well as connection costs to the main electrical grid being too high.
To decrease the effects of this driving force of inequality, To decrease the effects of this driving force of inequality,
both infrastructural expansion as well as policy commitments toward affordable connections to electrical grids are thus of vital importance. both infrastructural expansion as well as policy commitments toward affordable connections to electrical grids are thus of vital importance.
<!-- development assistance -->
```{python}
#| label: fig-ben-aid-donortype
#| fig-cap: "Total ODA for Benin per year, separated by donor type. Source: "
#| column: page
dfsub1 = pd.read_csv('data/raw/OECD_CRS/CRS1_Benin_11-13_05092022185506030.csv', parse_dates=True, low_memory=False)
dfsub2 = pd.read_csv('data/raw/OECD_CRS/CRS1_Benin_14-16_05092022192438936.csv', parse_dates=True, low_memory=False)
dfsub3 = pd.read_csv('data/raw/OECD_CRS/CRS1_Benin_17-20_05092022192856890.csv', parse_dates=True, low_memory=False)
df = pd.concat([dfsub1, dfsub2, dfsub3], ignore_index=True)
df = df.rename(columns={'\ufeff"DONOR"': 'DONOR'})
donortotals = totals_by_donortype(df)
donortotals_grouped = donortotals.groupby(['Donortype', 'Year']).agg({'Value': ['sum']})
donortotals_grouped = donortotals_grouped.reset_index(['Donortype', 'Year'])
donortotals_grouped.columns = donortotals_grouped.columns.to_flat_index()
donortotals_grouped.columns = ['Donortype', 'Year', 'Value']
fig = px.line(donortotals_grouped, x='Year', y='Value', color='Donortype', labels={"Value": "Development aid, in millions"}, markers=True, template="seaborn")
fig.show()
```

View file

@ -61,3 +61,182 @@ def plot_consumption_gini_percapita_ruralurban(country_df):
gini_plot(gni_cnsmpt) gini_plot(gni_cnsmpt)
``` ```
```{python}
## Set up functions to grab development aids by type of donating body
## ODA donor type map, see DAC code sheet xlsx
donortypes = {
1: 'dac',
2: 'dac',
3: 'dac',
4: 'dac',
5: 'dac',
6: 'dac',
7: 'dac',
8: 'dac',
9: 'dac',
10: 'dac',
11: 'dac',
12: 'dac',
18: 'dac',
20: 'dac',
21: 'dac',
22: 'dac',
40: 'dac',
50: 'dac',
61: 'dac',
68: 'dac',
69: 'dac',
75: 'dac',
76: 'dac',
301: 'dac',
302: 'dac',
701: 'dac',
742: 'dac',
801: 'dac',
820: 'dac',
918: 'dac',
104: 'multilat',
807: 'multilat',
811: 'multilat',
812: 'multilat',
901: 'multilat',
902: 'multilat',
903: 'multilat',
905: 'multilat',
906: 'multilat',
907: 'multilat',
909: 'multilat',
913: 'multilat',
914: 'multilat',
915: 'multilat',
921: 'multilat',
923: 'multilat',
926: 'multilat',
928: 'multilat',
932: 'multilat',
940: 'multilat',
944: 'multilat',
948: 'multilat',
951: 'multilat',
952: 'multilat',
953: 'multilat',
954: 'multilat',
956: 'multilat',
958: 'multilat',
959: 'multilat',
960: 'multilat',
963: 'multilat',
964: 'multilat',
966: 'multilat',
967: 'multilat',
971: 'multilat',
974: 'multilat',
976: 'multilat',
978: 'multilat',
979: 'multilat',
980: 'multilat',
981: 'multilat',
982: 'multilat',
983: 'multilat',
988: 'multilat',
990: 'multilat',
992: 'multilat',
997: 'multilat',
1011: 'multilat',
1012: 'multilat',
1013: 'multilat',
1014: 'multilat',
1015: 'multilat',
1016: 'multilat',
1017: 'multilat',
1018: 'multilat',
1019: 'multilat',
1020: 'multilat',
1023: 'multilat',
1024: 'multilat',
1025: 'multilat',
1037: 'multilat',
1038: 'multilat',
1311: 'multilat',
1312: 'multilat',
1313: 'multilat',
30: 'nondac',
45: 'nondac',
55: 'nondac',
62: 'nondac',
70: 'nondac',
72: 'nondac',
77: 'nondac',
82: 'nondac',
83: 'nondac',
84: 'nondac',
87: 'nondac',
130: 'nondac',
133: 'nondac',
358: 'nondac',
543: 'nondac',
546: 'nondac',
552: 'nondac',
561: 'nondac',
566: 'nondac',
576: 'nondac',
611: 'nondac',
613: 'nondac',
732: 'nondac',
764: 'nondac',
765: 'nondac',
1601: 'private',
1602: 'private',
1603: 'private',
1604: 'private',
1605: 'private',
1606: 'private',
1607: 'private',
1608: 'private',
1609: 'private',
1610: 'private',
1611: 'private',
1612: 'private',
1613: 'private',
1614: 'private',
1615: 'private',
1616: 'private',
1617: 'private',
1618: 'private',
1619: 'private',
1620: 'private',
1621: 'private',
1622: 'private',
1623: 'private',
1624: 'private',
1625: 'private',
1626: 'private',
1627: 'private',
1628: 'private',
1629: 'private',
1630: 'private',
1631: 'private',
1632: 'private',
1633: 'private',
1634: 'private',
1635: 'private',
1636: 'private',
1637: 'private',
1638: 'private',
1639: 'private',
}
def totals_by_donortype(oda_frame):
totals = oda_frame.loc[
(df['RECIPIENT'] == 236) &
(df['SECTOR'] == 1000) &
(df['FLOW'] == 100) &
(df['CHANNEL'] == 100) &
(df['AMOUNTTYPE'] == 'D') &
(df['FLOWTYPE'] == 112) &
(df['AIDTYPE'] == "100") # contains mixed int and string representations
]
donortotals = totals.copy()
donortotals["Donortype"] = donortotals["DONOR"].map(donortypes)
return donortotals
```