title: How to output spark data to a csv file with separate columns?
body: <p>My code 1st extracts data using a regex and writes that data to a text file (string format). 
  I then tried creating a dataframe out of the contents in the text file so that i can have separate columns which led to an error. (Writing it to a csv file writes the entire thing into just one column). </p>
  
  <pre><code>with open("C:\\Sample logs\\dataframe.txt",'a') as f:
      f.write(str(time))
      f.write(" ")
      f.write(qtype)
      f.write(" ")
      f.write(rtype)
      f.write(" ")
      f.write(domain)
      f.write("\n")
   new = sc.textFile("C:\\Sample logs\\dataframe.txt").cache() # cause df requires an rdd
   lines1 = new.map(lambda x: (x, ))
   df = sqlContext.createDataFrame(lines1)
  </code></pre>
  
  <p>But i get the following error:</p>
  
  <blockquote>
    <p>TypeError: Can not infer schema for type: type 'unicode'</p>
  </blockquote>
  
  <p>I tried some other ways but didn't help. All that I want to do is that after performing write operation, i want to create a dataframe that has separate columns in order to use groupBy(). </p>
  
  <p>The input in the text file:</p>
  
  <pre><code>1472128348.0 HTTP - tr.vwt.gsf.asfh
  1472237494.63 HTTP - tr.sdf.sff.sdfg
  1473297794.26 HTTP - tr.asfr.gdfg.sdf
  1474589345.0 HTTP - tr.sdgf.gdfg.gdfg
  1472038475.0 HTTP - tr.sdf.csgn.sdf
  </code></pre>
  
  <p>Expected output in csv format:</p>
  
  <blockquote>
    <p>The same thing as above but separated into columns so i can perform
    groupby operations.</p>
  </blockquote>