| Reference | Downloads | Github

Importing a CSV file for the purpose of using target times for target detection

I am creating an experiment in which I have two audio files playing at the same time. The participant has a dual task of listening to one of the audios(narrative) and answering questions later on, and listening to the second audio(target detection) and pressing a button every time they hear a certain word.

In the target detection task I have 4 conditions (own, other, 1target, 2targets). I have created a loop which takes an audio file(target detection) matching the specific condition randomly from my folder, and matches it with one of the narrative audio files(which it takes out of a condition list).

I want to provide the participants with feedback after every trial about how well they did on the target detection task. For this I need to have access to another excel or CSV spreedsheet from which to extract the actual target times and compare them with the detected times that the participant got in the experiment.

Is there anyway to import a CSV file to psychopy and use it in this way?

@DSP123, using Pandas would be a good option:

import pandas as pd
targData = pd.read_excel("yourExcel.xlsx")

# Access a variable
mean = targData["yourVariable"].mean()
SD = targData["yourVariable"].std()

Is there a reason that for the SD there are two equal marks?

If I just need to access three different target times for 3 different conditions can I just extract them as three different variables?

Also when I put in the second line in the code in the shell I get this error message:

targData = pd.read_excel(“datasheet.xlsx”)
Traceback (most recent call last):
File “”, line 1, in
TypeError: read_excel() takes at least 2 arguments (1 given)

Is there another argument I need to put in for read_excel besides the filename?

Ah no the extra = was a typ0 - I have edited the response.

The error suggests you are running an older version of Pandas. So, try adding the sheetname of your spreadsheet as well. E.g., :

targData = pd.read_excel("yourExcel.xlsx", "sheet1")

That is what I thought and I tried to add the sheetname but now I get another error

Is there any other function besides read_excel that I could use?

targData = pd.read_excel(“datasheet.xlsx”, “Sheet1”)

Traceback (most recent call last):

File “”, line 1, in

File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\pandas\io\”, line 51, in read_excel

return ExcelFile(path_or_buf,kind=kind).parse(sheetname=sheetname,

File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\pandas\io\”, line 67, in init

import xlrd # throw an ImportError if we need to

ImportError: No module named xlrd

@DSP123, you have several options.

  1. Install xlrd Python module for Psychopy - see docs
  2. Use importConditions function to import your excel file - see docs
  3. Use a newer version of PsychoPy with the latest compatible Pandas.

If you want to go online with this later, you won’t be able to use pandas or xlrd, fyi.