psychopy.org | Reference | Downloads | Github

Weird data.importConditions error when importing 2 of 3 identically structured files; third one works fine

I created three seemingly identically structured tab-delimited files (attached) for purposes of counterbalancing. Whereas gr_C_B.csv works fine, the other two raise “pandas.errors.ParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 3” (see log below). I have checked the files several times and can’t find an error. R or TAD have no problem reading them. What could be the reason?
Puzzled, Jochen

2020-04-29 00:43:40.051 python[69117:58521129] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
  File "/long/path/deleted/AB_grC_lastrun.py", line 363, in <module>
    trialList=data.importConditions("gr_C_"+expInfo['group']+".csv"),
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/data/utils.py", line 305, in importConditions
    sep=sep, dec=dec)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/data/utils.py", line 219, in _attemptImport
    sep=sep, decimal=dec)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/pandas/io/parsers.py", line 709, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/pandas/io/parsers.py", line 455, in _read
    data = parser.read(nrows)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/pandas/io/parsers.py", line 1069, in read
    ret = self._engine.read(nrows)
  File "/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/pandas/io/parsers.py", line 1839, in read
    data = self._reader.read(nrows)
  File "pandas/_libs/parsers.pyx", line 902, in pandas._libs.parsers.TextReader.read
  File "pandas/_libs/parsers.pyx", line 924, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas/_libs/parsers.pyx", line 978, in pandas._libs.parsers.TextReader._read_rows
  File "pandas/_libs/parsers.pyx", line 965, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas/_libs/parsers.pyx", line 2208, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 2 fields in line 3, saw 3

gr_C_A.csv (670 Bytes) gr_C_B.csv (671 Bytes) gr_C_C.csv (670 Bytes)

Hi Jochen,

I could reproduce your error and I’m trying to find out how to get rid of it.
Is it on purpose that you separate your values with tabs and not commas, even though you’re using a comma separated value file ending?

I suspect, what you are trying to do is upload a conditions file that looks like this, with the values separated by commas:

"condsFile","msg"
"AB_grC_3.csv","Fertig?\n\nIn diesem Block sollen Sie den farbigen Buchstaben ignorieren (einfach Leertaste drücken).\n\nIhre Aufgabe ist einfach zu berichten, ob anschließend ein X zusehen war (j) oder nicht (n)."
"AB_grC_1.csv","Fertig?\n\nIn diesem Block ist Ihre Aufgabe,\n\n(1) den farbigen Buchstaben zu berichten\n\nund\n\n(2) zu berichten, ob anschließend ein X zusehen war (j) oder nicht (n)."
"AB_grC_2.csv","Fertig?\n\nIn diesem Block ist Ihre Aufgabe,\n\n(1) zu berichten, ob der farbige Buchstabe rot (Pfeil nach oben) oder grün war (Pfeil nach unten)\n\nund\n\n(2) zu berichten, ob anschließend ein X zusehen war (j) oder nicht (n)."

If I import this file, the error is gone. And the shape of the imported data is (3,2) not (3,1) as was the case with your gr_C_B.csv file.

Thanks, so I will just use commas as separators, that’s an easy solution. I’m fairly new to PsychoPy and have got so used to using tabs as delimiters that I might have overlooked it. Funny enough, tabs used to work with earlier prototypes.

You’re welcome. If that solves your issue, you could mark the post as the solution :slight_smile:

Of course, I just did

1 Like