Randomly select every 4 row in condition file

You need to break the conditionType list into two lists for each type.

AffType = [1,2,3,4]
DenType = [1,2,3,4]
shuffle(AffType) 
shuffle(DenType)
stimList = pd.DataFrame(columns = list(dat.columns.values))  # Create blank dataframe

for stims in stimNum:
    stim = dat[dat['Num'] == stims]  # Get stim
    aff = stim[stim['Type'] == 0]  # Then get aff stim
    denial = stim[stim['Type'] == 1]  # Then get denial stim
    if len(AffType):
        # Randomize aff and denial stim by validity condition etc
        stimNum = AffType.pop()
        stimList = stimList.append(aff[aff['condition'] == stimNum], ignore_index = True)
        stimNum = DenType.pop()
        stimList = stimList.append(denial[denial['condition'] == stimNum], ignore_index = True)
    if not len(AffType):
        AffType = [1,2,3,4]
        DenType = [1,2,3,4]
        shuffle(AffType) 
        shuffle(DenType)
1 Like