Re: Problems with commas causing too many columns in CSV

692 views
Skip to first unread message

Marc Buehner

unread,
Jun 11, 2013, 3:44:15 AM6/11/13
to psychop...@googlegroups.com
Susie,
I just started using CSV files myself, so I am  not sure I understand what exactly your question is.
Do you mean your problem is with the wide data file your program generates?
Or do you have an analysis file that reads from your psydat file and generates a CSV file?
The latter is what I do, and I don't really have any problems, though I don't use many strings in my output.
But, for example, it happily displays a whole list (say, of RTs) in one comma-separated cell.

I don't have the time to wade through all the code you attached, so if you can separate the critical bits that would make it easier.
Have you tried using triple quotes to delineate whichever string it is that you try to save?
I think if you do that, it should keep commas etc inside it.
Another alternative I guess would be to scan your string for commas and try to strip them out.
But have a look at the psydat file and see what's in there. It might be a better way to get at what you need than the wide data format file anyway.

On Monday, June 10, 2013 3:31:32 PM UTC+1, Susanna Martin wrote:
Hi

I've been trying to write my own experiment in psychopy and so far it's going well! Basically I display a bit of text (called from a spreadsheet) and ask the participants to rate it on two scales, then it clicks onto the next statement.

This all works fine, however my problem is in my CSV output file. It is picking up on the commas in my display text and generating new columns which means my responses are out of sync with each other.
Does anybody have any suggestions for excluding the text commas from the CSV? An alternative is to not report the block of text in the CSV as it reports other data which allows me to deduce which statement, but i'm not sure how to do this either!
I've attached my py file,  the excel statements file which it calls and an example response file so you can see what the issue is.

Thanks in advance!

Susie

Jared Roberts

unread,
Jun 11, 2013, 10:55:39 AM6/11/13
to psychop...@googlegroups.com
Hi Susie,

I don't use the experiment handler myself, so there may be a better way of doing this.  However, my first guess would be that you would want to replace any commas in your statement with white space after you've used the in the experiment.

For example, I might do something like this:
   #Here you're storing off the statement with the comma in order to display it to your participant
    Statement=Trial['Statement']
  #Here we're replacing the commas in the original statement with white space.  Shouldn't affect display because you've already stored a copy
   Trial['Statement'] = Trial['Statement'].replace(","," ")

For a tutorial on python's string replace function, check here: http://www.tutorialspoint.com/python/string_replace.htm.  If you want to replace the comma with something else ( maybe a semicolon), just send ";" instead of " " as the second parameter.


Let me know if that works for you.
-Jared

--
Jared Roberts
Graduate Student
The Yassa Learning and Memory Laboratory
Johns Hopkins University
"A lost cause can be as spiritually satisfying as a victory." - Robert Heinlein

Dave Braze

unread,
Jun 11, 2013, 11:58:41 AM6/11/13
to psychop...@googlegroups.com
Rather than stripping commas, as Marc and Jared propose, you could also try
quoting any strings that contain commas before writing them to the csv file.
Most (?) programs that read csv files will, at least as an option, respect
quoted strings in the sense that they will not try to interpret commas within
quoted strings as column delimiters.

-Dave
> --
> You received this message because you are subscribed to the Google Groups
> "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/psychopy-users/CA%2B0fxeWv7s78M7q_aKyEsOrqt9dMqkhiuxPXs_fxMy0LPmabJw%40mail.gmail.com?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages