psychopy.org | Reference | Downloads | Github

Problem with randomisation

Hello,
First i’m sorry because i have a bad english, i will try to be clear. im trying to code an experiment on psychopy but i have a problem with the randomisation
i used : d = d.iloc[random.sample(d.index, len(d))]
d.inxdex = range(len(d))
and i have this output :
Traceback (most recent call last):
File “C:\Users\Florentina\Documents\memoire\Tâche FLT Absolue\script absolue.py”, line 39, in
d = d.iloc[random.sample(list(d).index, len(d))]
File “C:\Program Files (x86)\PsychoPy3\lib\random.py”, line 316, in sample
raise TypeError(“Population must be a sequence or set. For dicts, use list(d).”)
TypeError: Population must be a sequence or set. For dicts, use list(d).

whats that mean, how can i fix this problem.

NB: when i remove the randomisation code, the script work

thank you

Try this:

d = d.iloc[random.sample(list(d.index), len(d))]

The basic problem is that random.sample doesn’t recognize d.index as a list, so it doesn’t know what to do with it.

Thank you
its work :slight_smile: