#########################################
# task2 求出每个被试在不同position 和 condition下的正确率和反应时
# position表示该词出现的位置(1为上,-1为下),condition表示该词是高还是低(1为高,2为低)
#被试1,在条件1下的ACC和反应时
import codecs
import csv
import pandasas pd
import numpyas np
#############################读取数据
# readfile=codecs.open('d:\corcsv.csv','r','utf-8')#打开csv格式文件用csv.open库 如果是utf-8格式容易出错,用codecs库替代
# read=csv.DictReader(readfile)
path=r'd:\corcsv.csv'
read=pd.read_csv(path)
# print(read)
###########################################索引设定
# read.set_index(['subject','position','condition'],inplace=True)#设置三重索引、
read.reset_index(inplace=True)
#read2=read.dropna()#删除NaN
print(read)#前五行
########################################索引提取
# read.iloc[0]#利用行号提取
# print(read.iloc[0])
# print(read.loc[read['subject']==1])#loc 根据索引提取行
# print(read.query('subject=="1"'))
###########################提取单个被试单个条件下的数据
# s1p1c1
# s1=read.loc[read['subject']==1]
# s1p1=s1.loc[s1['position'] == -1]
# s1p1c1=s1p1.loc[s1p1['condition'] == 1]
# print(s1p1c1)
###########################循环提取所有被试四个条件下数据
A=[]
for iin [1,2,3,4,5]:
Sub=[]
s=read.loc[read['subject']== i]
for pin [1,-1]:
sp=s.loc[s['position']==p]
for cin [1,2]:
spc=sp.loc[sp['condition']==c]
# print(i,p,c,spc)
Sub.append(spc)
A.append(Sub)
网友评论