Hello,

I have an array 'summed_MWloss' which has the following content:
[0.00024064097412677081, 0.0010840802387205584, 0.003607376872954593, 0.0078014804983401742, 0.013657631815844617]

I am having trouble writing it into a CSV file into seperate rows. The code I am using at the moment is:

t = open(r'F:\IPSA\My_Work\Python_Files\my_powerD2.csv', 'w')
output = csv.writer(t, dialect='excel', delimiter=',')
output.writerow(summed_MWloss)

which allows me to create a CSV file with all numbers displayed in one row, but I want each number to be in seperate row like:
0.00024064097412677081
0.0010840802387205584
and so on..

Please help. I have literally spend ages on this problem but couldnt solve. Thanks

Recommended Answers

All 2 Replies

Try something simple like this ...

mylist = [
0.00024064097412677081, 
0.0010840802387205584, 
0.003607376872954593, 
0.0078014804983401742, 
0.013657631815844617
]


t = open(r'my_powerD2.csv', 'w')

for item in mylist:
    t.write(str(item)+'\n')

t.close()

Thank you so much. I spent many hours trying to do this and never realised it was a simple solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.