-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_graph.py
37 lines (27 loc) · 909 Bytes
/
create_graph.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
import pandas as pd
import json
def create_graph(input_file, output_file):
df = pd.read_csv(input_file)
data_top = df.columns
# print(data_top[2:])
adj_list = {}
for row in df.itertuples():
for col in data_top[2:]:
pair = [col, float(getattr(row, col))]
if row.name not in adj_list.keys():
adj_list[row.name] = []
adj_list[row.name].append(pair)
pair2 = [row.name, float(getattr(row, col))]
if col not in adj_list.keys():
adj_list[col] = []
adj_list[col].append(pair2)
# print(adj_list)
json_data = json.dumps(adj_list)
# open file for writing, "w"
f = open(output_file,"w")
# write json object to file
f.write(json_data)
# close file
f.close()
# example usage
create_graph("./dataset/STANDARD_VALUES.csv", "./dataset/adj_list.json")