Hi there,
I am currently facing problems from transferring a working psychopy coder script from one laptop to another (both Mac OS).
OS : Mac OS 10.15
PsychoPy version: 2020.2.5
Standard Standalone? Yes
What are you trying to achieve?: The script works perfectly on my personal laptop (Mac OS 10.14, PsychoPy v2020.1.2, Python 2.7.16), but it fails when I try to index the first column of an imported pandas data frame.
### Import packages ####
from psychopy import visual, core, clock, data, event, logging, gui
from psychopy.hardware import keyboard
from numpy.random import random, randint, normal, shuffle
import pandas as pd
import os
JTCblock1 = pd.read_csv('/Users/…/Main study/Materials_Instruments/Questionnaires_Tasks/fMRI/SessB/block_conditions/JTCblock1.csv')
block = JTCblock1
# Save block name
print(block)
print(block['Block_name'])
block_name = block['Block_name'][0]
print(block_name)
The data frame “block” looks like this if I print it (which is fine):
Block_name;Image;file_fish;file_fishlist;file_lakes
0 JTCblock1;1;/Users/ausleihe2/Documents/AMBIZIO…
1 JTCblock1;2;/Users/ausleihe2/Documents/AMBIZIO…
2 JTCblock1;3;/Users/ausleihe2/Documents/AMBIZIO…
3 JTCblock1;4;/Users/ausleihe2/Documents/AMBIZIO…
4 JTCblock1;5;/Users/ausleihe2/Documents/AMBIZIO…
5 JTCblock1;6;/Users/ausleihe2/Documents/AMBIZIO…
6 JTCblock1;7;/Users/ausleihe2/Documents/AMBIZIO…
7 JTCblock1;8;/Users/ausleihe2/Documents/AMBIZIO…
8 JTCblock1;9;/Users/ausleihe2/Documents/AMBIZIO…
9 JTCblock1;10;/Users/ausleihe2/Documents/AMBIZI…
I am interested in the value of the column “Block_name”.
If I run the code posted above, I get the following error message:
print(block[‘Block_name’])
Traceback (most recent call last):
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pandas/core/indexes/base.py”, line 2646, in get_loc
File “pandas/_libs/index.pyx”, line 111, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/index.pyx”, line 138, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘Block_name’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 1, in
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pandas/core/frame.py”, line 2800, in getitem
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/pandas/core/indexes/base.py”, line 2648, in get_loc
File “pandas/_libs/index.pyx”, line 111, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/index.pyx”, line 138, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘Block_name’
Solution attempts: I googled why that is, I re-started PsychoPy and my laptop, and re-installed Psychopy and Python. My interpretation is that the error is based on the pandas package (version is 1.0.3), but I do not know how to solve it and how to obtain the value of the first column.
I’d be really happy for any responses as I am so close to finishing the experiment…
Thanks!
Sarah