-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_gen.py
More file actions
73 lines (61 loc) · 2.45 KB
/
csv_gen.py
File metadata and controls
73 lines (61 loc) · 2.45 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
# with open ("musae_DE_edges_graphfile_cluster", "r") as read_f:
# with open("musae_DE_edges.csv", "w") as write_f:
# write_f.write("Source,Target,Weight\n")
# src = 1
# src_dict = {}
# for line in read_f:
# dst_list = line.split()
# dst_list_set = set(dst_list)
# for dst in dst_list_set:
# write_f.write(str(src) + "," + str(dst) + "," + str(dst_list.count(dst)) + "\n")
# # print(dst_list)
# src = src+1
# print("done")
# with open ("musae_ENGB_edges_graphfile_cluster", "r") as read_f:
# with open("musae_ENGB_edges_graphfile_cluster.csv", "w") as write_f:
# write_f.write("Source,Target,Weight\n")
# src = 1
# src_dict = {}
# for line in read_f:
# dst_list = line.split()
# dst_list_set = set(dst_list)
# for dst in dst_list_set:
# write_f.write(str(src) + "," + str(dst) + "," + str(dst_list.count(dst)) + "\n")
# # print(dst_list)
# src = src+1
# print("done")
# with open ("./cdeezer_europe_edges_graphfile_cluster", "r") as read_f:
# with open("deezer_europe_edges.csv", "w") as write_f:
# write_f.write("Source,Target,Weight\n")
# src = 1
# src_dict = {}
# for line in read_f:
# dst_list = line.split()
# dst_list_set = set(dst_list)
# for dst in dst_list_set:
# write_f.write(str(src) + "," + str(dst) + "," + str(dst_list.count(dst)) + "\n")
# # print(dst_list)
# src = src+1
# print("done")
# import networkx as nx
# G = nx.complete_graph(5)
# nx.draw(G)
import os
# file_list = os.listdir("./clustered_graphfile_dir")
file_list = ['facebook_ego_graphfile_test_cluster']
for f in file_list:
csv_file = f.replace("_graphfile_cluster","") + ".csv"
with open ("./clustered_graphfile_dir/" + f, "r") as read_f:
with open("./csv_dir/"+csv_file, "w") as write_f:
write_f.write("Source,Target,Weight\n")
src = 1
src_dict = {}
lines = read_f.readlines()
for line in lines[1:]:
dst_list = line.split()
dst_list_set = set(dst_list)
for dst in dst_list_set:
write_f.write(str(src) + "," + str(dst) + "," + str(dst_list.count(dst)) + "\n")
# print(dst_list)
src = src+1
print("done")