In [37]:
import pandas as pd
import re

In [136]:
mtdata = pd.read_csv('mousetrackercorrected.csv')

In [17]:
includelist = pd.read_csv('n=452 subjectID.csv', header = None)
includelist = includelist[0].values

In [137]:
mtdata.loc[mtdata['subject'].isin(includelist)]


Out[137]:
subject trial stimfile condition code resp_1 resp_2 response distractor error ... Y_92 Y_93 Y_94 Y_95 Y_96 Y_97 Y_98 Y_99 Y_100 Y_101

0 rows × 226 columns


In [181]:
mtdata['RESPONSE1'] = [x for x in mtdata['resp_1'].str.extract(r'..(\d*)_.(\d*)', expand = True).values]
mtdata['RESPONSE2'] = [x for x in mtdata['resp_2'].str.extract(r'..(\d*)_.(\d*)', expand = True).values]


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-181-e417fb0c78b3> in <module>()
      1 mtdata['RESPONSE1'] = [x for x in mtdata['resp_1'].str.extract(r'..(\d*)_.(\d*)', expand = True).values]
      2 mtdata['RESPONSE2'] = [x for x in mtdata['resp_2'].str.extract(r'..(\d*)_.(\d*)', expand = True).values]
----> 3 mtdata['RESPONSE1'] = [int(x) for x in mtdata['RESPONSE1']]
      4 mtdata['RESPONSE2'] = [int(x) for x in mtdata['RESPONSE2']]

TypeError: only length-1 arrays can be converted to Python scalars

In [141]:
mtdata['SELFISHCHOICESELFMORE'] = 0
mtdata['SELFISHCHOICEGROUPMORE'] = 0

In [155]:
mtdata.head()


Out[155]:
subject trial stimfile condition code resp_1 resp_2 response distractor error ... Y_96 Y_97 Y_98 Y_99 Y_100 Y_101 RESPONSE1 RESPONSE2 SELFISHCHOICESELFMORE SELFISHCHOICEGROUPMORE
0 455806 1 NaN 777 prac2 ~S3_O6.jpg ~S7_O8.jpg 1 1 1 ... 1.1400 1.1400 1.1400 1.1400 1.1400 1.1400 [3, 6] [7, 8] 0 0
1 455806 3 NaN 777 prac8 ~S5_O4.jpg ~S10_O11.jpg 1 1 1 ... 1.1500 1.1500 1.1500 1.1500 1.1500 1.1500 [5, 4] [10, 11] 0 0
2 455806 5 NaN 777 prac4 ~S5_O4.jpg ~S8_O9.jpg 1 2 0 ... 1.1250 1.1250 1.1250 1.1250 1.1250 1.1250 [5, 4] [8, 9] 0 0
3 455806 7 NaN 777 prac5 ~S10_O9.jpg ~S7_O8.jpg 1 1 1 ... 1.2125 1.2125 1.2125 1.2125 1.2125 1.2125 [10, 9] [7, 8] 0 0
4 455806 9 NaN 777 smgmvsslgl12 ~S14_O10.jpg ~S9_O12.jpg 1 2 0 ... 1.1900 1.1900 1.1900 1.1900 1.1900 1.1900 [14, 10] [9, 12] 0 0

5 rows × 230 columns

if error == 0, then selfish, and that's response 1? if 1 then altruistic

ERROR 0 REPSPONSE 0 ERROR 1 RESPONSE 0 ERROR 0 RESPONSE 1 ERROR 1 RESPONSE 1


In [171]:
tempdata = pd.DataFrame(columns = ('RESPONSE','ERROR','RESPONSE1','RESPONSE2'))
tempdata['RESPONSE'] = mtdata['response']
tempdata['ERROR'] = mtdata['error']
tempdata['RESPONSE1'] = mtdata['RESPONSE1']
tempdata['RESPONSE2'] = mtdata['RESPONSE2']
tempdata['SELFISHCHOICESELFMORE'] = 0
tempdata['SELFISHCHOICEGROUPMORE'] = 0

In [172]:
tempdata.head()


Out[172]:
RESPONSE ERROR RESPONSE1 RESPONSE2 SELFISHCHOICESELFMORE SELFISHCHOICEGROUPMORE
0 1 1 [3, 6] [7, 8] 0 0
1 1 1 [5, 4] [10, 11] 0 0
2 1 0 [5, 4] [8, 9] 0 0
3 1 1 [10, 9] [7, 8] 0 0
4 1 0 [14, 10] [9, 12] 0 0

In [204]:
SELFISHCHOICESELFMORE = []
SELFISHCHOICEGROUPMORE = []

for row in tempdata.iterrows():
    if (row[1][0] == 1) & (row[1][1] == 0) | ((row[1][0] == 2) & (row[1][1] == 1)):
        try:
            SELFISHCHOICESELFMORE.append(int(row[1][2][0]) - int(row[1][3][0]))
            SELFISHCHOICEGROUPMORE.append((int(row[1][2][0]) + int(row[1][2][1])) - (int(row[1][3][0]) + int(row[1][3][1])))
        except:
            SELFISHCHOICESELFMORE.append(None)
            SELFISHCHOICEGROUPMORE.append(None)
    elif ((row[1][0] == 2) & (row[1][1] == 0)) | ((row[1][0] == 1) & (row[1][1] == 1)):
        try:
            SELFISHCHOICESELFMORE.append(int(row[1][3][0]) - int(row[1][2][0]))
            SELFISHCHOICEGROUPMORE.append((int(row[1][3][0]) + int(row[1][3][1])) - (int(row[1][2][0]) + int(row[1][2][1])))
        except:
            SELFISHCHOICESELFMORE.append(None)
            SELFISHCHOICEGROUPMORE.append(None)


  File "<ipython-input-204-a20c7951e5a0>", line 9
    except:
         ^
SyntaxError: invalid syntax

In [202]:
tempdata['SELFISHCHOICESELFMORE'] = SELFISHCHOICESELFMORE

In [203]:
tempdata


Out[203]:
RESPONSE ERROR RESPONSE1 RESPONSE2 SELFISHCHOICESELFMORE SELFISHCHOICEGROUPMORE
0 1 1 [3, 6] [7, 8] 4.0 0
1 1 1 [5, 4] [10, 11] 5.0 0
2 1 0 [5, 4] [8, 9] -3.0 0
3 1 1 [10, 9] [7, 8] -3.0 0
4 1 0 [14, 10] [9, 12] 5.0 0
5 2 0 [8, 10] [11, 7] 3.0 0
6 2 0 [10, 11] [12, 9] 2.0 0
7 1 0 [11, 7] [5, 9] 6.0 0
8 1 1 [7, 8] [10, 5] 3.0 0
9 1 1 [6, 8] [8, 5] 2.0 0
10 2 1 [11, 6] [7, 10] 4.0 0
11 1 1 [6, 11] [13, 10] 7.0 0
12 2 1 [12, 8] [9, 11] 3.0 0
13 1 0 [11, 6] [8, 12] 3.0 0
14 1 0 [nan, nan] [nan, nan] NaN 0
15 1 1 [6, 9] [10, 5] 4.0 0
16 1 1 [9, 12] [10, 5] 1.0 0
17 1 0 [12, 8] [7, 9] 5.0 0
18 1 0 [12, 8] [7, 11] 5.0 0
19 1 0 [12, 8] [9, 12] 3.0 0
20 2 1 [11, 6] [8, 9] 3.0 0
21 1 1 [6, 8] [9, 5] 3.0 0
22 1 0 [14, 10] [6, 11] 8.0 0
23 2 0 [9, 10] [11, 8] 2.0 0
24 1 0 [10, 6] [5, 9] 5.0 0
25 1 0 [9, 6] [7, 8] 2.0 0
26 1 0 [13, 8] [10, 13] 3.0 0
27 2 0 [7, 8] [10, 5] 3.0 0
28 2 0 [8, 11] [12, 7] 4.0 0
29 1 0 [15, 10] [9, 14] 6.0 0
... ... ... ... ... ... ...
875 1 0 [12, 8] [9, 12] 3.0 0
876 1 1 [8, 10] [11, 7] 3.0 0
877 1 1 [6, 8] [8, 5] 2.0 0
878 1 0 [13, 10] [10, 14] 3.0 0
879 1 0 [11, 6] [8, 11] 3.0 0
880 1 0 [14, 10] [9, 12] 5.0 0
881 1 0 [14, 9] [9, 13] 5.0 0
882 2 0 [6, 7] [8, 5] 2.0 0
883 2 0 [7, 8] [9, 6] 2.0 0
884 2 1 [10, 5] [7, 8] 3.0 0
885 2 1 [12, 7] [8, 11] 4.0 0
886 2 0 [7, 10] [11, 6] 4.0 0
887 1 0 [nan, nan] [nan, nan] NaN 0
888 2 1 [10, 7] [8, 9] 2.0 0
889 2 0 [6, 9] [10, 5] 4.0 0
890 2 1 [11, 7] [8, 10] 3.0 0
891 2 0 [7, 9] [10, 6] 3.0 0
892 2 0 [9, 10] [12, 7] 3.0 0
893 2 0 [9, 10] [11, 8] 2.0 0
894 2 1 [13, 8] [9, 12] 4.0 0
895 2 0 [6, 8] [9, 5] 3.0 0
896 2 0 [6, 7] [8, 5] 2.0 0
897 2 1 [12, 9] [10, 11] 2.0 0
898 2 0 [10, 11] [13, 8] 3.0 0
899 1 0 [nan, nan] [nan, nan] NaN 0
900 2 1 [10, 5] [7, 8] 3.0 0
901 2 1 [11, 6] [8, 9] 3.0 0
902 2 0 [9, 11] [12, 8] 3.0 0
903 2 1 [12, 8] [9, 11] 3.0 0
904 2 1 [9, 5] [6, 8] 3.0 0

905 rows × 6 columns