Stratified random selection from datafile

Hi,

I have a csv file which contains my stimuli for import.
There are 64 trials which are spilt into 4 conditions i.e. 16 stimuli in each condition (1,2,3,4). This value is saved in the column ‘Conditions’.

I want to assign half the trials to one condition in my experiment and half to another - so I need to create two lists/arrays that I can then use separately.
So the data needs to be spilt into two sets of 32 trials, with each sets containing 8 stimuli from each condition. I want this to be randomly selected for each participant.

I’m unsure how to go about this. I can’t use a random selection, as it’s not guaranteed that there will be equal amount of each condition in the two data sets. I have seen online you can do stratified sampling using the sklearn module, however when I try to import this to psychopy it says it does not exist.
So far I have:

df=pd.read_csv(‘AP_AU_conditions_new.csv’, sep=’;’)
df.groupby(‘Condition’)

How can I select 8 rows from each condition randomly and put this into a list/array. And have the remain rows in another list/array?

Thanks,
Emma

1 Like