title: Specifying the filename when saving a DataFrame as a CSV
body: <p>Say I have a Spark DF that I want to save to disk a CSV file.  In Spark 2.0.0+, one can convert <strong><code>DataFrame(DataSet[Rows])</code></strong> as a <strong><code>DataFrameWriter</code></strong> and use the <strong><code>.csv</code></strong> method to write the file.</p>
  
  <p>The function is defined as </p>
  
  <pre><code>def csv(path: String): Unit
      path : the location/folder name and not the file name.
  </code></pre>
  
  <p>Spark stores the csv file at the location specified by creating CSV files with name - part-*.csv.</p>
  
  <p>Is there a way to save the CSV with specified filename instead of part-*.csv ? Or possible to specify prefix to instead of part-r ?</p>
  
  <p><strong>Code :</strong></p>
  
  <pre><code>df.coalesce(1).write.csv("sample_path")
  </code></pre>
  
  <p><strong>Current Output :</strong></p>
  
  <pre><code>sample_path
  |
  +-- part-r-00000.csv
  </code></pre>
  
  <p><strong>Desired Output :</strong></p>
  
  <pre><code>sample_path
  |
  +-- my_file.csv
  </code></pre>
  
  <p><strong>Note :</strong> The coalesce function is used to output a single file and the executor has enough memory to collect the DF without memory error. </p>