|
1 | 1 | import glob
|
2 | 2 | import pandas as pd
|
3 | 3 | import numpy as np
|
| 4 | +import csv |
4 | 5 |
|
5 | 6 | path ='C:/Users/cac20/PycharmProjects/python_projects/lba_model2/'
|
6 | 7 | allFiles = glob.glob(path + "*.txt")
|
7 | 8 |
|
8 |
| -print len(allFiles[0]) |
| 9 | + |
9 | 10 | # Lists we'll need later as well as pandas data frames
|
10 | 11 | # filenameframe = pd.DataFrame()
|
11 | 12 | frame = pd.DataFrame()
|
12 |
| -list_ = [] |
| 13 | +drt_list = [] |
13 | 14 | # conds = []
|
14 | 15 | # rename = []
|
15 | 16 | # subids = ['001', '002', '003', '004', '005', '006', '007', '008', '009', '010',
|
|
20 | 21 | # cond = str(filename[4:6])
|
21 | 22 | # conds.append(cond)
|
22 | 23 | #
|
23 |
| -# |
24 | 24 | # i = 1
|
25 | 25 |
|
| 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) |
26 | 52 |
|
27 | 53 |
|
28 |
| -for filename in allFiles: |
29 |
| - filename = filename[58:] |
30 |
| - subid = str(filename[13:16]) |
31 |
| - cond = str(filename[16]) |
32 | 54 |
|
33 | 55 |
|
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 }) |
37 | 56 |
|
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' |
48 | 68 |
|
49 | 69 |
|
50 | 70 | # df = pd.concat([pd.Series(i, name = "subid"),pd.Series(conds[i], name = "condition"), df], axis = 1)
|
51 | 71 |
|
52 | 72 |
|
53 | 73 | # i = i + 1
|
54 | 74 |
|
55 |
| - list_.append(df) |
| 75 | + # list_.append(df) |
56 | 76 |
|
57 | 77 |
|
58 |
| -frame = pd.concat(list_) |
59 | 78 |
|
60 |
| -frame.to_csv('complete/complete_data.csv') |
| 79 | +# frame.to_csv('complete/complete_data.csv') |
61 | 80 |
|
0 commit comments