title: Fastest way to write large CSV with Python
body: <p>I want to write some random sample data in a csv file until it is 1GB big. Following code is working:</p>
  
  <pre><code>import numpy as np
  import uuid
  import csv
  import os
  outfile = 'data.csv'
  outsize = 1024 # MB
  with open(outfile, 'ab') as csvfile:
      wtr = csv.writer(csvfile)
      while (os.path.getsize(outfile)//1024**2) &lt; outsize:
          wtr.writerow(['%s,%.6f,%.6f,%i' % (uuid.uuid4(), np.random.random()*50, np.random.random()*50, np.random.randint(1000))])    
  </code></pre>
  
  <p>How to get it faster?</p>