Writing multiple outputs to .csv

Hi -

I want to compare the output of a wta module to 4 different outcome vectors. The way I did this was to create 4 compare modules. My problem is how to save the output.

What I tried is:

with open('June14b_Stroop'+  '.csv', 'w') as outfile:
    for data in sim.data[probe_cf_red_phonology]:
        outfile.write(','.join([str(d) for d in data]) + '\n') 

    for data in sim.data[probe_cf_green_phonology]:
        outfile.write(','.join([str(d) for d in data]) + '\n') 

    for data in sim.data[probe_cf_blue_phonology]:
        outfile.write(','.join([str(d) for d in data]) + '\n') 

    for data in sim.data[probe_cf_black_phonology]:
        outfile.write(','.join([str(d) for d in data]) + '\n') 

This create one column of data. If I run the sim for 1000 msec, I get 4000 data points. The outcome for red is in the first 1000 values, the outcomes for green in the 2nd 1000 values, etc.

What I want to do is write it to 4 separate columns.

I assume this is trivial for someone who knows python coding.

Thanks

Hi @HowardC,

Try this out:

with open('June14b_Stroop' + '.csv', 'w') as outfile:
    # Optional header line
    outfile.write('red,green,blue,black')
    for i in range(sim.n_steps):
        outfile.write('%s,%s,%s,%s\n' % (
            sim.data[probe_cf_red_phonology][i],
            sim.data[probe_cf_green_phonology][i],
            sim.data[probe_cf_blue_phonology][i],
            sim.data[probe_cf_black_phonology][i],
        ))

Thanks

Howard