# Stratified random selection from datafile

**URL:** <https://discourse.psychopy.org/t/stratified-random-selection-from-datafile/2986>\
**Category:** Coding\
**Created:** [August 31, 2017, 2:36pm UTC](https://discourse.psychopy.org/t/stratified-random-selection-from-datafile/2986 "2017-08-31T14:36:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmathompson](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@emmathompson](https://discourse.psychopy.org/u/emmathompson)\
**Post date:** [August 31, 2017, 2:36pm UTC](https://discourse.psychopy.org/t/stratified-random-selection-from-datafile/2986/1 "2017-08-31T14:36:22Z")

</div>

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
