Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 771c699

Browse files
committed
Added data for parsing to python_projects. Git is trying to make lba_model2 its own repository.
1 parent 5f8a0bf commit 771c699

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

subid_cond.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import glob
22
import pandas as pd
33
import numpy as np
4+
import csv
45

56
path ='C:/Users/cac20/PycharmProjects/python_projects/lba_model2/'
67
allFiles = glob.glob(path + "*.txt")
78

8-
print len(allFiles[0])
9+
910
# Lists we'll need later as well as pandas data frames
1011
# filenameframe = pd.DataFrame()
1112
frame = pd.DataFrame()
12-
list_ = []
13+
drt_list = []
1314
# conds = []
1415
# rename = []
1516
# subids = ['001', '002', '003', '004', '005', '006', '007', '008', '009', '010',
@@ -20,42 +21,60 @@
2021
# cond = str(filename[4:6])
2122
# conds.append(cond)
2223
#
23-
#
2424
# i = 1
2525

26+
for change in allFiles:
27+
with open(change, 'r') as f:
28+
change = change[58:]
29+
subid = str(change[13:16])
30+
cond = str(change[16])
31+
data = f.readlines()
32+
for line in data:
33+
line = line.split()
34+
line.insert(0, subid + cond)
35+
for spot in line:
36+
if spot[0:3] == 'DRT':
37+
drt_list.append(line)
38+
39+
print drt_list[0:2]
40+
41+
42+
43+
with open("output.csv", "wb") as f:
44+
writer = csv.writer(f)
45+
writer.writerows(drt_list)
46+
47+
# in_txt = np.genfromtxt(change, delimiter=',', dtype=str)
48+
# print in_txt
49+
# out_csv = csv.writer(open(change, 'wb'))
50+
#
51+
# out_csv.writerows(in_txt)
2652

2753

28-
for filename in allFiles:
29-
filename = filename[58:]
30-
subid = str(filename[13:16])
31-
cond = str(filename[16])
3254

3355

34-
df = pd.read_csv(filename,index_col=None, header=0)
35-
mapping = {'correct': 1, 'Wrong!!': 0, 'miss': -1}
36-
df = df.replace({'correct': mapping, 'wrong': mapping, 'miss': mapping })
3756

38-
if filename[:3] == subid:
39-
if filename[4:6] == 'Co':
40-
df['subid'] = subid
41-
df['condition'] = '1'
42-
elif filename[4:6] == 'ST':
43-
df['subid'] = subid
44-
df['condition'] = '2'
45-
else:
46-
df['subid'] = subid
47-
df['condition'] = '3'
57+
# df = pd.read_csv(filename,index_col=None, header=0)
58+
# mapping = {'correct': 1, 'wrong': 0, 'miss': -1}
59+
# df = df.replace({'correct': mapping, 'wrong': mapping, 'miss': mapping })
60+
#
61+
# if filename[13:16] == subid:
62+
# if filename[16] == 'a':
63+
# df['subid'] = subid
64+
# df['condition'] = '1'
65+
# else:
66+
# df['subid'] = subid
67+
# df['condition'] = '2'
4868

4969

5070
# df = pd.concat([pd.Series(i, name = "subid"),pd.Series(conds[i], name = "condition"), df], axis = 1)
5171

5272

5373
# i = i + 1
5474

55-
list_.append(df)
75+
# list_.append(df)
5676

5777

58-
frame = pd.concat(list_)
5978

60-
frame.to_csv('complete/complete_data.csv')
79+
# frame.to_csv('complete/complete_data.csv')
6180

0 commit comments

Comments
 (0)