title: How to repartition Spark dataframe depending on row count?
body: <p>I wrote a simple program that request a huge database. To export my result, I wrote this function:</p>
  
  <pre><code>result.coalesce(1).write.options(Map("header" -&gt; "true", "delimiter"  &gt; ";")).csv(mycsv.csv)
  </code></pre>
  
  <p>I use the <code>coalesce</code> method to have only get one file as an output. The problem is that the result file contains more than one million lines. So, I couldn't open it in Excel...</p>
  
  <p>So, I thought about using a method (or write my own function using a for loop) that can create partitions related to the number of the lines in my file. But I have no idea how can I do this.</p>
  
  <p>My idea is that if I have less than one million line, I will have one partition. If I have more than one million => two partitions, 2 millions => 3 partitions and so on.</p>
  
  <p>Is it possible to do something like this?</p>