jeudi 21 décembre 2017

not so random selection of word in a dataframe Python

I'm trying to create a stroop test. The stroop test is a cognitive test where a word is given the word is a color, but the ink of the word change every time. For exemple, we can have the word BLEU in ink red, in this case it is non congruent because the word BLEU(blue) is not the same than the ink.

The participant needs to say the color of the ink and not the word. So, it is harder to answer if the word wrote is the not same than the ink.

Every time a new participant comes in, I want a new sequence of word/ink.

So, I created this code :

import pandas as pd
import numpy as np
import random

word = ['bleu', 'rouge', 'vert', 'jaune']

ink = ['blue', 'red', 'green', 'yellow']

my_list_word = [random.choice(word) for _ in range(60)]

df = pd.DataFrame(my_list_word, columns=["word"])

my_list_ink = [random.choice(ink) for _ in range(60)]

df['ink'] = my_list_ink

df['response'] = df['ink']

df['response'] = df['response'].replace(['red'], 'rouge.jpg')
df['response'] = df['response'].replace(['yellow'], 'jaune.jpg')
df['response'] = df['response'].replace(['blue'], 'bleu.jpg')
df['response'] = df['response'].replace(['green'], 'vert.jpg')

di = dict(zip(word, ink))
df['congruent'] = (df['word'].map(di) == df['ink']).astype(int)

print df.head(5)

df(head) :

    word     ink   response  congruent
0   vert    blue   bleu.jpg          0
1   bleu    blue   bleu.jpg          1
2  rouge    blue   bleu.jpg          0
3  jaune     red  rouge.jpg          0
4   vert  yellow  jaune.jpg          0

My question : I need to have 50% of the time a congruent question. Do you have ideas for how to do that ? I don't understand how to link two columns for a condition. Maybe, I could translate the french word, so it would be the same word, easier to compare. And at the end, I translate it for my experimentation ?

Thanks for your help!




Aucun commentaire:

Enregistrer un commentaire