In [112]:
import pandas as pd
import os
rootdir = 'C:/Users/Bryan/Desktop/MT_corrected'

Loop through all MT files

We loop through all the files in the data directory, and for each, report the subject ID, and their answer for the self-check.


In [171]:
def self_chips(line):
    pid = ""
    answer = ""
    for i, char in enumerate(line):
        if i <= 6:
            pid = str(pid) + str(char)
        if i > 63 and i < 67:
            answer = answer + char
    return [pid, answer]

In [172]:
def all_participant_colors(rootdir):    
    participant_colors = []
    
    for subdir, dirs, files in os.walk(rootdir):
        for file in files:
            file_name = open(rootdir + "/" + file)
        
            for i, line in enumerate(file_name):
                try:
                    if i > 4 and i < 75 and line[23] == 'Y':  
                        participant_colors.append(self_chips(line))
                except IndexError:
                    pass
            file_name.close()
    return participant_colors

In [173]:
hopefully_this_works = all_participant_colors(rootdir)

In [174]:
hopefully_this_works = pd.DataFrame(hopefully_this_works)

In [175]:
hopefully_this_works.to_csv("answer.csv", index = False, header = False)

In [176]:



Out[176]:
0 1
0 0007233 GRE
1 0037708 RED
2 0040990 GRE
3 0130537 GRE
4 0230565 GRE
5 0281545 RED
6 0324007 GRE
7 0401074 RED
8 0428211 GRE
9 0501550 RED
10 0598036 GRE
11 0691488 RED
12 0704231 GRE
13 1033973 RED
14 1053045 GRE
15 1514297 GRE
16 1890123 RED
17 1970418 RED
18 2034574 RED
19 2112773 GRE
20 2121400 RED
21 2259822 RED
22 2343035 RED
23 2434247 GRE
24 2457677 RED
25 2490930 RED
26 2563027 GRE
27 2577468 RED
28 2597349 RED
29 2615292 GRE
... ... ...
103 7734056 RED
104 7951976 GRE
105 8028695 GRE
106 8037607 GRE
107 8062504 GRE
108 8098942 RED
109 8190859 GRE
110 8319592 RED
111 8330797 GRE
112 8386031 RED
113 8598376 GRE
114 8607805 RED
115 8707506 GRE
116 9032163 GRE
117 9147029 RED
118 9183695 RED
119 9268317 RED
120 9305859 GRE
121 9475563 RED
122 9501676 GRE
123 9514415 RED
124 9517576 RED
125 9528114 RED
126 9634156 RED
127 9684033 GRE
128 9732217 RED
129 9916669 GRE
130 9937074 GRE
131 9986486 GRE
132 9986562 GRE

133 rows × 2 columns