A pandas DataFrame column duration
contains timedelta64[ns]
as shown. How can you convert them to seconds?
0 00:20:32
1 00:23:1
This works properly in the current version of Pandas (version 0.14):
In [132]: df[:5]['duration'] / np.timedelta64(1, 's')
Out[132]:
0 1232
1 1390
2 1495
3 797
4 1132
Name: duration, dtype: float64
Here is a workaround for older versions of Pandas/NumPy:
In [131]: df[:5]['duration'].values.view('
timedelta64 and datetime64 data are stored internally as 8-byte ints (dtype
'
Note that you need NumPy version 1.7 or newer to work with datetime64/timedelta64s.