pandas converts datetime objects to np.datetime64 objects, the differences of which are np.timedelta64 objects.
Consider this
In [30]: df Out[30]: 0 1 0 2014-02-28 13:30:19.926778 2014-02-28 13:30:47.178474 1 2014-02-28 13:30:29.814575 2014-02-28 13:30:51.183349
I can consider the difference in columns on
df[0] - df[1] Out[31]: 0 -00:00:27.251696 1 -00:00:21.368774 dtype: timedelta64[ns]
and therefore I can apply the timedelta64 transformations. For microseconds
(df[0] - df[1]).apply(lambda x : x.astype('timedelta64[us]'))
or microseconds as integers
(df[0] - df[1]).apply(lambda x : x.astype('timedelta64[us]').astype('int')) 0 -27251696000 1 -21368774000 dtype: int64
EDIT: As suggested by @Jeff, recent expressions can be abbreviated as
(df[0] - df[1]).astype('timedelta64[us]')
and
(df[0] - df[1]).astype('timedelta64[us]').astype('int')
for pandas> = .13.
Acorbe
source share