Thouph commited on
Commit
6c31714
1 Parent(s): ad1c63b

Upload convert.py

Browse files
Files changed (1) hide show
  1. convert.py +37 -0
convert.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ csv.field_size_limit(1000000000)
3
+
4
+ if __name__ == '__main__':
5
+ # get md5 to all other properties map
6
+ md5_to_row = dict()
7
+ with open("posts-2023-09-14.csv", "r", encoding="utf-8") as input_file:
8
+ reader = csv.reader(input_file)
9
+ header = next(reader)
10
+
11
+ for row in reader:
12
+ # row[3] is md5
13
+ this_map = {row[3]:row}
14
+ md5_to_row.update(this_map)
15
+
16
+ # get all aesthetic ratings
17
+ aesthetic_score_rows = []
18
+ with open("aesthetic_scores_t3.4_q90.csv", "r", ) as input_file_2:
19
+ reader = csv.reader(input_file_2)
20
+ _ = next(reader)
21
+ for row in reader:
22
+ aesthetic_score_rows.append(row)
23
+
24
+
25
+ with open("output.csv", "w", encoding="utf-8", newline="") as output_file:
26
+ writer = csv.writer(output_file)
27
+ header.append("aesthetic_score")
28
+ writer.writerow(header)
29
+
30
+ for row in aesthetic_score_rows:
31
+ this_md5 = row[1]
32
+ if this_md5 in md5_to_row.keys():
33
+ this_row = md5_to_row[row[1]]
34
+ this_row.append(row[-1])
35
+ writer.writerow(this_row)
36
+
37
+