| Reference | Downloads | Github

Error with saveAsWideText


I usually add a bit of code to my Builder experiments after each block of trials to save participants’ data into a single .csv file containing data for all participants, e.g.

Block_loop.saveAsWideText(“AnimalStroop_allParticipants.csv”, delim=’,’, matrixOnly=True, appendFile=True)

This is currently not working in one of my experiments and I can’t figure out why: It works fine in another very similar experiment. Any help would be much appreciated. The error message is:

Block_loop.saveAsWideText("AnimalStroop_allParticipants.csv", delim=',', matrixOnly=True, appendFile=True)

File “/Users/lpzjwp/code/psychopy/git/psychopy/data/”, line 696, in saveAsWideText
File “/Applications/”, line 4319, in append
File “/Applications/”, line 1737, in union
indexer = self.get_indexer(other)
File “/Applications/”, line 2082, in get_indexer
raise InvalidIndexError('Reindexing only valid with uniquely’
pandas.indexes.base.InvalidIndexError: Reindexing only valid with uniquely valued Index objects

I’ve attached the code for the two experiments. I’m running psychopy 1.85.4 on Mac OS 10.12.6

Animal (26.7 KB) (26.0 KB)


If they are actually Builder-generated files, can we see the .psyexp files instead?


The .psyexp files are attached. The relevant code is in a code component in the End_block/End_block_1 routine.

works.psyexp (61.5 KB)

doesnt_work.psyexp (60.7 KB)

  1. Just out of interest, why are you doing this, given that Builder will save the data automatically?
  2. You should disable saving Excel files: performance wise, it is more trouble than its worth (we really should deprecate that feature).
  3. What happens if you use thisExp.saveAsWideText() instead? (i.e. ask the ExperimentHandler to save the data rather than the TrialHandler).

  1.   There are a few reasons for this: Firstly, I find this the easiest way to put data from all participants into a single file for subsequent data analysis in SPSS. The reason I like to do this for each block rather than the whole experiment is that then I only get data for the main trials of interest and also if participants don’t complete the task (I work with children so this happens quite a lot) then I still get some data.
  2.   Thanks, that’s useful advice.
  3.   I put thisExp.saveAsWideText() at the end of the experiment and it works. It’s not as good for me as saving at the TrialHandler level but at least it’s putting everything into one file for those that complete the experiment.

Thanks for your help.


This is all a bit mysterious, as you shouldn’t actually need to explicitly call thisExp.saveAsWideText() at the end of the experiment, as this should happen automatically as long as you set saveWideText=True when creating the ExperimentHandler.

If the experiment ends normally (even if it terminates early) the data should be saved. The only exception would be if you exit the experiment by pushing the red ‘stop’ button. If you terminate in a more civilised fashion (e.g. end early in response to the escape key, and then call core.quit()), then the normal housekeeping will occur.

None of this addresses your issue with the calling .saveAsWideText() from the TrialHandler though…