title: How to save a DataFrame to a csv file in spark 1.6?
body: <p>I'm working on a dataframe which contains two columns, uni_key and createdDate. I run an SQL query and save the results into <code>a</code>, and now i want to save these results onto a csv file. Is there any way to do this? Here's a code snippet:</p>
  
  <pre><code>import sys
  from pyspark import SparkContext
  from pyspark.sql import SQLContext, Row
  import csv
  
  
  
  if len(sys.argv) != 2:
  
      print("Usage: cleaning_date.py &lt;file&gt;")
      exit(-1)
  sc = SparkContext()
  sqlContext = SQLContext(sc)
  csvfile = sc.textFile("new_311.csv")
  key_val = csvfile.mapPartitions(lambda x: csv.reader(x)).map(lambda x: (x[0], x[1]))
  result = key_val.filter(lambda x: getDataType(x[1]) == "valid")
  myDataFrame = sqlContext.createDataFrame(result, ('uni_key', 'createdDate'))
  print(type(myDataFrame))
  myDataFrame.registerTempTable("abc")
  a = sqlContext.sql("SELECT uni_key FROM abc")
  a.show()
  # a.write.format("com.databricks.spark.csv").save("l.csv")
  a.write.option("header", "true").csv("aaa.csv")
  sc.stop()
  </code></pre>
  
  <p>this code gives the following error right now:</p>
  
  <p>AttributeError: 'DataFrameWriter' object has no attribute 'csv'</p>