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]:
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]
In [141]:
mtdata['SELFISHCHOICESELFMORE'] = 0
mtdata['SELFISHCHOICEGROUPMORE'] = 0
In [155]:
mtdata.head()
Out[155]:
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]:
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)
In [202]:
tempdata['SELFISHCHOICESELFMORE'] = SELFISHCHOICESELFMORE
In [203]:
tempdata
Out[203]: