SFrames and date time differences.

User 2568 | 4/14/2016, 8:59:45 AM

I'm working on calculating Customer Lifetime Value and need to compute the differences between the End and Start dates for each row in an SFrame. I noticed subtracting two datetime SArrays is not permitted , i.e., the following shorthand does not work.

customer['Period'] = customer['End'] - customer['Start'] 

So I thought I'd do it long hand using applyt, but SFrame does not accept date differences, i.e., the following does not work.

customer['Period'] = customer.apply(lambda row: customer['End'] - customer['Start'] )

in the end the solution was to store the result as a number of days.

customer['Period'] = customer.apply(lambda row: (customer['End'] - customer['Start'] ).days)

My suggestion is to 1. Support the shorthand of subtracting two dates 2. Allow a SArray or SFrame column to hold a datetime difference.

Its a minor suggestion really.


User 15 | 4/14/2016, 5:48:08 PM

Hi @Kevin_McIsaac,

Thanks for the suggestion. Could you open an issue here: ?

The main issue here is the time interval type support, which is something we've discussed but thus far haven't implemented. You can bet we'd support the shorthand if we supported the output type.

You can just cast the datetime columns to type int and that will be the number of seconds after the UNIX epoch, and then use the shorthand subtraction in the meantime.