-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloadDataTest.py
More file actions
46 lines (39 loc) · 1.18 KB
/
Copy pathloadDataTest.py
File metadata and controls
46 lines (39 loc) · 1.18 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
import csv
import numpy as np
from os.path import realpath, dirname
'''
# This works with non-excel generated .csv
with open('Book2.csv', 'rb') as f:
reader = csv.reader(f)
your_list = list(reader)
'''
# do this to go around the excel-generated csv issue
# filepath saves local file Book2.csv
filepath = realpath('../../Book2.csv')
print(filepath)
with open(filepath, newline='', encoding='utf-8-sig') as f:
reader = csv.reader(f)
# This skips the first row of the CSV file.
next(reader)
alert_list = list(reader)
# alert_dic: dictionary use alertID(alert[0]) as the key, saves text and label
alert_dic = {}
for alert in alert_list:
if alert[0] in alert_dic:
alert_dic[alert[0]][0] += "; " + alert[1]
else:
alert_dic[alert[0]] = [alert[1], alert[2]]
# print(alert[0])
# inputData as the list to save the text and label
# input[0] as the text description
# inpit[1] as the label
inputData = [[]]
for id, content in alert_dic.items():
#print(id, ":", content)
content[1] = int(content[1]) # change string label to int label(0,1)
inputData.append(content)
for data in inputData:
if not data:
continue
else:
print(data)