Keep getting KeyError: u''
Hello! I'm trying to setup my self paced word training sequence, but I keep getting a keyerror with the following error message:
Error while executing inline script item-stack: experiment[run].training_2[run].nonword_sequence_2[prepare].nonword_disp_2[prepare] exception type: KeyError exception message: u'' item: nonword_disp_2 time: Mon Mar 25 12:05:01 2019 phase: prepare Traceback: File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\inline_script.py", line 77, in prepare self.experiment.python_workspace._exec(self.cprepare) File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\base_python_workspace.py", line 124, in _exec exec(bytecode, self._globals) Inline script, line 2, in <module> KeyError: u''
My nonword_disp_2 inline script is as follows:
#mapped with wordorder variable in loop table. var.set('nonword_2', wordmap_2[var.get('wordorder')])
I thought that it was an issue with my nonword lists not having the unicode prefix, but even after I prefixed them with u, I keep getting this error. I am only getting this keyerror with my second lexicon (nonwords_2/wordmap_2), but not my first lexicon (nonwords_1/wordmap_1). I have attached the relevant part of my exp as well as the spreadsheets that are my loop tables.
Comments
When does the error occur? I just tried ~50 trials for each loop and I can't reproduce the error.
You could also try to load the excel file in an inline_script and check whether each word was read correctly.
Eduard
Hi Eduard,
Turns out it was an error with my excel spreadsheet! Thanks for your help.
This annoying error means that Pandas can not find your column name in your dataframe. Before doing anything with the data frame, use print(df.columns) to see dataframe column exist or not.
print(df.columns)
I was getting a similar kind of error in one of my codes. Turns out, that particular index was missing from my data frame as I had dropped the empty dataframe 2 rows. If this is the case, you can do df.reset_index(inplace=True) and the error should be resolved.