title: Split Spark Dataframe into train and test
body: <p>I want to split my Spark Dataframe into train and test with the following conditions -</p>
  <ol>
  <li>I want to be able to reproduce the split, which means that for each
  time for the same DataFrame, I will be able to to the same split.</li>
  <li>The split should be taken from each unique value of a column name sequence-id.</li>
  </ol>
  <p>Currently, I do it by converting the Dataframe into Pandas Dataframe and doing the following -</p>
  <pre><code>test_padnas = df.toPandas()
  train_frac = 0.8
  
  train = test_padnas.sort_values(by='sequence_id','timestamp']).groupby('sequence_id',group_keys=False).apply(lambda df: df.sample(frac=train_frac,random_state=200))
  test=test_padnas.drop(train.index)
  </code></pre>