-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenMapCSV.py
More file actions
51 lines (43 loc) · 1.34 KB
/
genMapCSV.py
File metadata and controls
51 lines (43 loc) · 1.34 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
import csv
import numpy as np
country_rates = {}
country_rate_vector = {}
with open("Datasets/clean/cdo_emissions.csv", "rb") as csvfile:
datareader = csv.reader(csvfile)
for line in datareader:
# print line
country_name = line[0]
country_code = line[1]
country_vector = line[2:]
country_rate = []
prev_val = None
curr_val = None
for cdoval in country_vector:
try:
curr_val = float(cdoval)
if(prev_val != None):
country_rate.append(curr_val - prev_val)
prev_val = curr_val
except ValueError:
pass
country_rate_vector[country_code] = np.array(country_rate)
for country in country_rate_vector:
country_rates[country] = np.mean(country_rate_vector[country])
print country_rates
max = 0
argmax = 0
meanv = 0
for i in country_rates:
meanv += country_rates[i]
if(country_rates[i] > max):
max = country_rates[i]
argmax = i
print meanv/len(country_rates)
print argmax, max
# with open('Datasets/clean/cdo_map.csv', 'w') as f: # Just use 'w' mode in 3.x
# f.write("country,rate_value")
# f.write("\n")
# for country in country_rates:
# f.write(str(country) + ",")
# f.write(str(country_rates[country]))
# f.write("\n")