How to create a csv file of data created in python
<p>I am new to programming. I was wondering if anyone can help me create a csv file for the data that I created in python.
My data looks like this</p>

<pre><code>import numpy as np
print np.__version__



a = 0.75 + (1.25 - 0.75)*np.random.sample(10000)
print a
b = 8 + (12 - 8)*np.random.sample(10000)
print b
c = -12 + 2*np.random.sample(10000)
print c
x0 = (-b - np.sqrt(b**2 - (4*a*c)))/(2*a)
print x0
</code></pre>

<p>The csv file format I am looking to create is 1 column each for a,b,c and x0 (see example below)</p>

<p><a href="http://i.stack.imgur.com/AnAcF.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/AnAcF.jpg" alt="enter image description here"></a></p>

<p>Your expert assistance will be highly appreciated</p>

<p>Thanks in advance :-)</p>

<p>Edit 1>>
Input code:</p>

<pre><code>import numpy as np
print np.__version__
import csv




a = 0.75 + (1.25 - 0.75)*np.random.sample(10000)
##print a
b = 8 + (12 - 8)*np.random.sample(10000)
##print b
c = -12 + 2*np.random.sample(10000)
##print c
x0 = (-b - np.sqrt(b**2 - (4*a*c)))/(2*a)
##print x0


with open("file.csv",'w') as f:
    f.write('a,b,c,x0\n')
    for val in a,b,c,x0:
        print val
        f.write(','.join(map(str,[a,b,c,x0]))+ '\n')
</code></pre>

<p>Output
<a href="http://i.stack.imgur.com/M6rcv.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/M6rcv.jpg" alt="enter image description here"></a></p>

<p>I am being able to generate the data using for loop command (see pic below). The csv format is not outputting as expected. </p>

<p><a href="http://i.stack.imgur.com/mhplU.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/mhplU.jpg" alt="enter image description here"></a></p>

<pre><code>with open("file.csv",'w') as f:
  f.write('a,b,c,x0\n')
  --forloop where you generate a,b,c,x0:
    f.write(','.join(map(str,[a,b,c,x0])) + '\n')
</code></pre>

python python-2.7 python-3.x csv export-to-csv