title: Split a data frame into two or more data frames in Scala using spark
body: <p>I have got a dataset of 2 million records. I want to split it into 2 equal half's . I don't have any column with serial number so that I can apply a where condition over it and split it into 2. That may not be the right approach also but all i want to do is split a dataframe into 2 half's </p>
  
  <p>sample code that i am using:</p>
  
  <pre><code>var invoiceData = sc.textFile("/Scala/InvoiceLine.csv");
  def removeheader (x : RDD[String]): RDD[String] = {
    x.mapPartitionsWithIndex((idx, lines) =&gt; {
      if (idx == 0) {
        lines.drop(1)
      }
      lines
    })
  }
  var invoiceWithoutHeader = removeheader(invoiceData);
  var invoiceSchemaString = invoiceData.first().toUpperCase().split(",").map(_.trim());
  var invoiceSchema = StructType(invoiceSchemaString.map(fieldName =&gt; StructField(fieldName, StringType, true)))
  var invoiceRowRDD = invoiceWithoutHeader.map(y =&gt; {
    var parser = new CSVParser(',');
    parser.parseLine(y)
  }).map { x =&gt; Row.fromSeq(x) } 
  var invoiceDF = sqlContext.applySchema(invoiceRowRDD, invoiceSchema);
  </code></pre>
  
  <p>Now I want to split the invoiceDF into 2 parts, 1 million each
  as I am a beginner, The code may not be efficient excuse me.</p>
  
  <p>Thanks in advance :)</p>