-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze_top_candidate.py
41 lines (23 loc) · 988 Bytes
/
analyze_top_candidate.py
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
import json
import pandas as pd
TO_PERCENT = 1000 / 100 # 10
def analyze_to_csv(f, file_path):
Uniform = json.load(f)
# ["0"] - ["0"] / 1000 * 100
data_out = pd.DataFrame()
data = []
for pol_dim in Uniform["Ranked_Choice"]["3"]:
data.append(int(pol_dim))
data_out["Politics Dim"] = data
for key in Uniform["Ranked_Choice"]:
data = []
for pol_dim in Uniform["Ranked_Choice"][key]:
rc_val = Uniform["Ranked_Choice"][key][pol_dim]["0"] # number of best winner
fc_val = Uniform["First_Past_Post"][key][pol_dim]["0"] # number of best winner
data.append((rc_val - fc_val) / TO_PERCENT)
data_out[key] = data
data_out.to_csv(file_path, index=None)
with open('data/Normal_3_Candidates.json', 'r', encoding='utf-8') as f:
analyze_to_csv(f, "data/Normal.csv")
with open('data/Uniform_All_Candidates.json', 'r', encoding='utf-8') as f:
analyze_to_csv(f, "data/Uniform.csv")