Randomizing between two columns from an Excel file

Hi! :smiling_face:

I am working on a primed Lexical Decision Task. In my experiment there are two types of targets - words and pseudowords. I made an Excel spreadsheet just for training purposes and here it is:
image
What I am trying to achieve is for PsychoPy to randomly present stimuli from one of the two first columns (a word or a pseudoword), in such a way that, for example: if PSEUDOWORD3 has been shown already, WORD3 won’t be shown anymore, and if WORD7 has been shown, then PSEUDOWORD7 won’t be.
I am completely new to coding and so I am trying to rely on builder functions, however I think that this time some basic code will be necessary.
How do I achieve that with minimal code?

Hi @Julia_Mazurek,

You can indeed achieve this with just a little bit of code. There are a couple of ways to achieve the same thing, but I’ve attached a small demo of how I would approach it (the demo is built in version 2024.1.4).
word_pseudoword_demo.zip (12.2 KB)

The demo chooses whether to present the word or pseudoword on each trial, and will not present ‘word1’ if ‘pseudoword1’ has already been presented.

Do let me know if there are any issues!

Kim

Thank you @Kimberley_Dundas!
Your code has helped me a lot. I was wondering if I could apply that same logic to four columns, with four other types of letter strings. Would that be possible?

Hi @Julia_Mazurek,

You could list the names of the columns, shuffle them, and choose one to present. Something like the following in a Begin Routine tab of a code component:

# Make a list of your column names
list_of_col_names = [col1, col2, col3, col4]

# Shuffle it
shuffle(list_of_col_names)

# Choose the first thing on the list to present
this_word = list_of_col_names[0]

Then you would use $this_word in the text field of a text component in the same way as I did in my demo.

Hope this helps!

Kim

1 Like