-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-labeling.py
More file actions
53 lines (35 loc) · 1.32 KB
/
data-labeling.py
File metadata and controls
53 lines (35 loc) · 1.32 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
"""
This is the script used to combine all collected csv data files into
a single csv file.
"""
import numpy as np
import csv
import time
import labels
# print the available class label (see labels.py)
act_labels = labels.activity_labels
print(act_labels)
# specify the data files and corresponding activity label
csv_files = ["data/Walking-Accelerometer.csv", "data/Running-Accelerometer.csv", "data/Sitting-Accelerometer.csv", "data/Jumping-Accelerometer.csv"]
activity_list = ["walking", "running", "sitting","jumping"]
# Specify final output file name.
output_filename = "data/all_labeled_data.csv"
all_data = []
zip_list = zip(csv_files, activity_list)
for f_name, act in zip_list:
if act in act_labels:
label_id = act_labels.index(act)
else:
print("Label: " + act + " NOT in the activity label list! Check label.py")
exit()
print("Process file: " + f_name + " and assign label: " + act + " with label id: " + str(label_id))
with open(f_name, "r") as f:
reader = csv.reader(f, delimiter = ",")
headings = next(reader)
for row in reader:
row.append(str(label_id))
all_data.append(row)
with open(output_filename, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(all_data)
print("Data saved to: " + output_filename)