-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine.py
44 lines (34 loc) · 1.21 KB
/
combine.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
41
42
43
import os
import sys
import csv
import argparse
parser = argparse.ArgumentParser(description='Combine several CSV produced by collect.py into one (for comparison).')
parser.add_argument('csv_output_file', help='The CSV file to create.')
parser.add_argument('csv_input_files', help='The CSV files to combine.', nargs='+')
args = parser.parse_args()
output_file = args.csv_output_file
files = args.csv_input_files
results = {}
n = len(files)
for i in range(n):
file = files[i]
with open(file, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
first = True
for row in reader:
if first:
first = False
continue
if not (row[0] in results):
results[row[0]] = [(None, None) for _ in range(n)]
results[row[0]][i] = [row[1],row[2]]
with open(output_file, 'w', newline='') as csv_f:
writer = csv.writer(csv_f, delimiter=',')
columns = ["Model name"]
for file in files:
columns += [file + " AT", file + " TT"]
writer.writerow(columns)
for i, k in enumerate(results):
v = results[k]
row = [k] + [item for sublist in v for item in sublist]
writer.writerow(row)