Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

I want to write a list of 2500 numbers into csv file.
From the code below, I only manage to get the list written in one row with 2500 columns in total. My expectation is to have 25 columns, where after every 25 numbers, it will begin to write into the next row.

Expected:
0.81 0.87 0.17 0.31......... 0.76(25th)
0.31.........................0.10(50th)

What I have tried:

csv_output = csv.writer(open("c.csv", "wb"))
    csv_output.writerow(["Col1","Col2","Col3","Col4","Col5","Col6","Col7","Col8","Col9","Col10","Col11","Col12","Col13","Col14","Col15","Col16","Col17","Col18","Col19","Col20","Col21","Col22","Col23","Col24","Col25"])




    i=0
    for row in csv_f2:
        print ("Superpixel features",row)
        a = float(row[0])

        for row2 in csv_f1:
                b = float(row2[i])
                c = (b-a)
                print ("%.8f, %.8f, %.8f" % (a, b, c))
                # save the feature vector using CSV 
                outputf = ([c])
                outf.append(outputf)
                csv_output.writerow(outf)
        f1.seek(0)
        i=i+1
Posted
Updated 7-May-18 5:22am
Comments
Richard MacCutchan 7-May-18 11:25am    
There is too much information missing from your question.

1 solution

Quote:
From the code below, I only manage to get the list written in one row with 2500 columns in total. My expectation is to have 25 columns, where after every 25 numbers, it will begin to write into the next row.

You need to count the numbers you outputs, and every time you reach 25, add a newline to output.
Is it a problem for you ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900