-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataPreprocessing.py
More file actions
173 lines (146 loc) · 5.74 KB
/
Copy pathdataPreprocessing.py
File metadata and controls
173 lines (146 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'''
VI - Project 1
DETI, UA, 2019/20
Title: Dataset Preprocessing Script
Description: Python script to extract the intended fields from the original
dataset in order to use them in our D3 Web Application.
Authors: Filipe Pires [85122] and Joao Alegria [85048]
'''
import csv
import collections
import json
reducedDataset = collections.OrderedDict()
reducedDataset["H.SH.TBS.INCD"] = {}
reducedDataset["G.VC.IHR.PSRC.P5"] = {}
reducedDataset["A.SH.STA.WASH.P5"] = {}
reducedDataset["F.SH.STA.SUIC.P5"] = {}
reducedDataset["I.SH.HIV.INCD.ZS"] = {}
reducedDataset["J.SH.MLR.INCD.P3"] = {}
reducedDataset["E.SH.DYN.NMRT"] = {}
reducedDataset["D.SH.DYN.MORT"] = {}
reducedDataset["C.SP.DYN.IMRT.IN"] = {}
reducedDataset["K.SH.MED.NUMW.P3"] = {}
reducedDataset["B.SP.DYN.AMRT.P3"] = {} #reducedDataset["SP.DYN.AMRT.FE"] = {} #reducedDataset["SSP.DYN.AMRT.MA"] = {}
csvfile = open('dataset/WDIData.csv', newline="")
datasetReader = csv.DictReader(csvfile)
ctr = 0
dataFemale = []
for row in datasetReader:
if ctr < 67258:
ctr += 1
continue
data = []
### Require no additional changes:
# Incidence of tuberculosis (per 100,000 people)
if row["Indicator Code"] == "SH.TBS.INCD":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(float(row[str(i)]))
reducedDataset["H.SH.TBS.INCD"][row["Country Code"]] = data
continue
# Intentional homicides (per 100,000 people)
if row["Indicator Code"] == "VC.IHR.PSRC.P5":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(float(row[str(i)]))
reducedDataset["G.VC.IHR.PSRC.P5"][row["Country Code"]] = data
continue
# Mortality rate attributed to unsafe water, unsafe sanitation and lack of hygiene (per 100,000 population)
if row["Indicator Code"] == "SH.STA.WASH.P5":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(float(row[str(i)]))
reducedDataset["A.SH.STA.WASH.P5"][row["Country Code"]] = data
continue
# Suicide mortality rate (per 100,000 population)
if row["Indicator Code"] == "SH.STA.SUIC.P5":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(float(row[str(i)]))
reducedDataset["F.SH.STA.SUIC.P5"][row["Country Code"]] = data
continue
### Require conversion to per 100, 000 population
# Incidence of HIV (per 1,000 uninfected population ages 15-49)
if row["Indicator Code"] == "SH.HIV.INCD.ZS":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(round(float(row[str(i)])*100,2))
reducedDataset["I.SH.HIV.INCD.ZS"][row["Country Code"]] = data
continue
# Incidence of malaria (per 1,000 population at risk)
if row["Indicator Code"] == "SH.MLR.INCD.P3":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(round(float(row[str(i)])*100,2))
reducedDataset["J.SH.MLR.INCD.P3"][row["Country Code"]] = data
continue
# Mortality rate, neonatal (per 1, 000 live births)
if row["Indicator Code"] == "SH.DYN.NMRT":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(round(float(row[str(i)])*100,2))
reducedDataset["E.SH.DYN.NMRT"][row["Country Code"]] = data
continue
# Mortality rate, under-5 (per 1, 000 live births)
if row["Indicator Code"] == "SH.DYN.MORT":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(round(float(row[str(i)])*100,2))
reducedDataset["D.SH.DYN.MORT"][row["Country Code"]] = data
continue
# Mortality rate, infant(per 1, 000 live births)
if row["Indicator Code"] == "SP.DYN.IMRT.IN":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(round(float(row[str(i)])*100,2))
reducedDataset["C.SP.DYN.IMRT.IN"][row["Country Code"]] = data
continue
# Nurses and midwives (per 1,000 people)
if row["Indicator Code"] == "SH.MED.NUMW.P3":
for i in range(1960,2020):
if row[str(i)]=="":
data.append(None)
else:
data.append(round(float(row[str(i)])*100,2))
reducedDataset["K.SH.MED.NUMW.P3"][row["Country Code"]] = data
continue
### Require merging and conversion to per 100, 000 population
# Mortality rate, adult, female(per 1, 000 female adults)
if row["Indicator Code"] == "SP.DYN.AMRT.FE":
for i in range(1960,2020):
if row[str(i)]=="":
dataFemale.append(None)
else:
dataFemale.append(float(row[str(i)]))
continue
# Mortality rate, adult, male(per 1, 000 male adults)
if row["Indicator Code"] == "SP.DYN.AMRT.MA":
for i in range(1960,2020):
if row[str(i)]=="" or dataFemale[i-1960]==None:
data.append(None)
else:
data.append(round((float(row[str(i)])+dataFemale[i-1960])/2*100,2))
dataFemale = []
reducedDataset["B.SP.DYN.AMRT.P3"][row["Country Code"]] = data # note that the code was altered!
continue
#print(reducedDataset)
with open('dataset/reducedDataset.json', 'w') as rd:
json.dump(reducedDataset, rd)