| Reference | Downloads | Github

Copying data from one routine to others

OS MacOS 10.15.3
PsychoPy version 3.2.4
Standard Standalone? (y/n) y

Hey everyone,

So I’m designing an experiment where I randomly pair a list of faces with 5 job titles in an encoding task. To do this, I set a randomizer called “dice” to randomly draw 5 numbers, then an if statement that takes whichever number was drawn and ties it to the face, repeating 45 times.

So I inserted a code component in the encoding routine to make the position randomizer. The code looks like this:

dice = np.random.randint(5, size = 1)

if dice == 0:
    title = "Vice President"
elif dice == 1:
    title = "Director"
elif dice == 2:
    title = "Middle Manager"
elif dice == 3:
    title = "Entry-level Employee"
elif dice == 4:
    title = "Support Staff"
    title = "None"

thisExp.addData("jobTitle", title)

This seems to work, but the issue I’m having is that there’s a recognition task that includes 90 faces, 45 of which were seen previously and 45 foils. I can’t seem to get the code to take the job titles that were applied in the encoding task and have them paired with the same faces in the recognition task. I’ve either had them all paired with “None” or one of the other titles.

What did you try to make it work?:

I inserted a code component in the recognition routine where I tried writing an if statement that takes the job title from the data and applies it to a new name, like this:

if title == 0:
    recogTitle = "Vice President"
elif title == 1:
    recogTitle = "Director"
elif title == 2:
    recogTitle = "Middle Manager"
elif title == 3:
    recogTitle = "Entry-level Employee"
elif title == 4:
    recogTitle = "Support Staff"
    recogTitle = "None"

thisExp.addData("recTitle", recogTitle)

I’ve tried statements that replace the word “title” with “dice” or “jobTitle” and neither has worked out the way I need.

Hi @retracy1

I think you can pair titles with faces at the beginning of the experiment in your condition file. I am not sure if it is the best way of doing that or if it is what you are looking for, but you can add a dice number and a title in front of each face in your condition file. Then you can use those titles in the following routines. Here is the code to add a title to each row randomly:

In the Begining Experiment Tab:

import pandas as pd
import numpy as np

# read your dataframe: Change the name of the file to your condition file!!!
df = pd.read_csv("your_condition.csv")

# generate random numbers. How many? As many as you dataframe length
dice = np.random.randint(5, size = len(df))

# add those numbers as a column to your dataframe
df['dice'] = dice

# add title based on those random numbers as a column to your dataframe
df['title'] = np.where(df['dice']== 0, 'Vice President', '')
df['title'] = np.where(df['dice']== 1, 'Director', df['title'])
df['title'] = np.where(df['dice']== 2, 'Middle Manager', df['title'])
df['title'] = np.where(df['dice']== 3, 'Entry-level Employee', df['title'])
df['title'] = np.where(df['dice']== 4, 'Vice Support Staff', df['title'])

#save your dataframe
df.to_csv ("your_condition.csv")


Thank you! This worked perfectly!

1 Like