Using .apply() in Sframes to manipulate multiple columns of each row
<p>I have an SFrame with the columns Date1 and Date2.</p>

<p>I am trying to use <code>.apply()</code> to find the datediff between Date1 and Date2, but I can't figure out how to use the other argument.</p>

<p>Ideally something like  </p>

<pre><code>frame['new_col'] = frame['Date1'].apply(lambda x: datediff(x,frame('Date2')))
</code></pre>

<p>You can directly take the difference between the dates in column <code>Date2</code> and those in <code>Date1</code> by just subtracting <code>frame['Date1']</code> from <code>frame['Date2']</code>. That, for some reason, returns the number of seconds between the two dates (only tested with python's <code>datetime</code> objects), which you can convert into <em>number of days</em> with simple arithmetics:</p>

<pre><code>from sframe import SFrame
from datetime import datetime, timedelta

mydict = {'Date1':[datetime.now(), datetime.now()+timedelta(2)], 
          'Date2':[datetime.now()+timedelta(10), datetime.now()+timedelta(17)]}
frame = SFrame(mydict)
frame['new_col'] = (frame['Date2'] - frame['Date1']).apply(lambda x: x//(60*60*24))
</code></pre>

<p>Output:</p>

<pre><code>+----------------------------+----------------------------+---------+
|           Date1            |           Date2            | new_col |
+----------------------------+----------------------------+---------+
| 2016-10-02 21:12:14.712556 | 2016-10-12 21:12:14.712574 |   10.0  |
| 2016-10-04 21:12:14.712567 | 2016-10-19 21:12:14.712576 |   15.0  |
+----------------------------+----------------------------+---------+
</code></pre>

python sframe