我一直试图简单地分析响应时间的数据,因为不可能为每个参与者手动完成。但是,由于某些原因,我的代码似乎无法正常工作。因此,基本上想看一下精度为1且prob_trial为1的块1到4的响应时间,但是我的代码显然不允许我这样做。你有什么建议吗?
我的csv文件内容如下:
Block,Trial_number,Position,Probability Position,Probability State,Probability trial,Response,Accuracy,RT (ms)
1,1,N,None,None,1,N,1,976.451326394
1,2,X,None,None,1,X,1,935.360659205
1,3,M,0.9,0.81,2,M,1,936.700751889
1,4,Z,0.81,None,2,Z,1,904.942057532
1,5,X,0.9,0.81,2,X,1,952.641545009
1,6,Z,0.81,None,2,Z,1,553.098919248
我的代码是这样的:
for fnam in d_list:
if fnam[-4:] == '.csv':
f_in = path1 + '/' + fnam
with open(f_in) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
block_no.append(int(row['Block']))
trial_no.append(int(row['Trial_number']))
prob_trial.append(int(row['Probability trial']))
accuracy.append(int(row['Accuracy']))
rt.append(float(row['RT (ms)']))
for x in block_no:
if x < 5:f
for y in accuracy:
if y == 1:
for z in prob_trial:
if z == 1:
epoch1_improbable.append(rt)
epoch1_improbable_rt = mean(epoch1_improbable)
答案 0 :(得分:1)
这是pandas的完美用例,通过它可以获得您想要的结果
import pandas as pd
df = pd.read_csv('data.csv')
mask = (df['Block'] < 5) & (df['Accuracy'] == 1) & (df['Probability trial'] == 1)
print(df[mask]['RT (ms)'].mean()) # 955.9059927994999