-
Notifications
You must be signed in to change notification settings - Fork 1
/
export_results.py
46 lines (35 loc) · 1.38 KB
/
export_results.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
44
45
#!/usr/bin/env python
# Need to have argparse installed:
# $ pip install argparse
import sys
import os.path
import argparse
from pandas import DataFrame
def read_data(data):
lines = data.readlines()
feature, precision, recall, f1 = [], [], [], []
for line in lines:
line_clean = line.strip().split(",")
feature.append(line_clean[0])
precision.append(line_clean[1])
recall.append(line_clean[4])
f1.append(line_clean[6])
return feature, precision, recall, f1
def save_to_spreadsheet(resultfile, data):
try:
df = DataFrame({'Feature': data[0], 'Precision': data[1], 'Recall': data[2], 'f1-score': data[3]})
df.to_csv(resultfile, index=False)
print("Spreadsheet saved at {0}".format(resultfile))
except:
print("Error: {0}".format(sys.exc_info()[0]))
def menu():
parser = argparse.ArgumentParser(description='Copy data results into a spreadsheet.')
parser.add_argument('-s', dest='input', type=argparse.FileType('r'), required=True, help="File with the results.")
parser.add_argument('-d', dest='output', required=True, help="The name of the file to save the spreadsheet.")
args = parser.parse_args()
args.input, args.output
return args.input, args.output
if __name__ == "__main__":
datafile, resultfile = menu()
data = read_data(datafile)
save_to_spreadsheet(resultfile, data)