-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleaner.py
49 lines (42 loc) · 1.44 KB
/
cleaner.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
46
47
48
49
import csv
import numpy as np
from numpy import genfromtxt
DIR = "/home/kt-fitz/data/raw/"
def crop_data(oldfile):
filename =oldfile[:oldfile.rfind('set')+5]+"-clean.csv"
datanames = genfromtxt(oldfile,delimiter=',',dtype=str)
columns = datanames[0,:]
with open(filename, 'w') as csvfile:
testwriter = csv.writer(csvfile,delimiter = ',')
testwriter.writerow(columns)
data = genfromtxt(oldfile,delimiter=',',dtype=float)
data = np.delete(data,0,0)
for i in range(0,np.shape(data)[0]):
if data[i,1]<=10.0:
row = data[i,:]
with open(filename,'a') as csvfile:
testwriter = csv.writer(csvfile,delimiter=',')
testwriter.writerow(row)
return
filetypes = {
1:"_c_set01_mda.csv",
2:"_apple_v_set02_mda.csv",
3:"_apple_h_set02_mda.csv",
4:"_apple_p_set03_mda.csv",
5:"_banana_v_set02_mda.csv",
6:"_banana_h_set02_mda.csv",
7:"_banana_p_set03_mda.csv",
8:"_house_v_set02_mda.csv",
9:"_house_h_set02_mda.csv",
10:"_house_p_set03_mda.csv",
11:"_umbrella_v_set02_mda.csv",
12:"_umbrella_h_set02_mda.csv",
13:"_umbrella_p_set03_mda.csv",}
for subj in range(15,16):
substr = str(subj).zfill(2)
print "Cleaning data of subject ", substr
for f in range(1,14):
try:
crop_data(DIR+"s"+substr+filetypes[f])
except:
print "No file of type s"+substr+filetypes[f]