title: Split or merge actions by date
body: <p>I like to create a sequence database, based on different activities (ACT) on same or different dates. As you can see, some rows may contain NaN values. I need the final data to train a machine learning model on sequences of activities.</p>
  
  <pre><code>ID  ACT1        ACT2        ACT3        ACT4        ACT5    
  0   2015-08-11  2015-08-16  2015-08-16  2015-09-22  2015-08-19
  1   2014-07-16  2014-07-16  2014-09-16  NaT         2014-09-12
  2   2016-07-16  NaT         2017-09-16  2017-09-16  2017-12-16
  </code></pre>
  
  <p>The expected output, which will split or merge based on the date values, would look like following table:</p>
  
  <pre><code>ID Sequence1  Sequence2  Sequence3  Sequence4  
  0  ACT1       ACT2,ACT3  ACT5       ACT4
  1  ACT1,ACT2  ACT5       ACT3
  2  ACT1       ACT3,ACT4  ACT5
  </code></pre>
  
  <p>Following script will output a string with the whole sequence only:</p>
  
  <pre><code>df['Sequence'] = df.loc[:, cols].apply(lambda dr: ','.join(df.loc[:, cols].columns[dr.dropna().argsort()]), axis=1)
  
  Sequence
  ACT1,ACT2,ACT3,ACT5,ACT4
  ACT1,ACT2,ACT5,ACT3
  ACT1,ACT3,ACT4,ACT5
  </code></pre>