Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time difference in seconds from numpy.timedelta64

How to get time difference in seconds from numpy.timedelta64 variable?

time1 = '2012-10-05 04:45:18' time2 = '2012-10-05 04:44:13' dt = np.datetime64(time1) - np.datetime64(time2) print dt  0:01:05 

I'd like to convert dt to number (int or float) representing time difference in seconds.

like image 546
sashkello Avatar asked Feb 17 '13 12:02

sashkello


People also ask

Does Numpy have datetime?

Starting in NumPy 1.7, there are core array data types which natively support datetime functionality. The data type is called datetime64 , so named because datetime is already taken by the Python standard library.

What is datetime64 in Numpy?

datetime64() method, we can get the date in a numpy array in a particular format i.e year-month-day by using numpy. datetime64() method. Syntax : numpy.datetime64(date) Return : Return the date in a format 'yyyy-mm-dd'.

What is timedelta64?

timedelta64() « Pandas date & time « Pandas « Numpy. Date and time calculations using Numpy timedelta64. Different units are used with timedelta64 for calculations, the list of units are given at the end of this tutorial. Let us create DataFrame with two datetime columns to calculate the difference.


1 Answers

To get number of seconds from numpy.timedelta64() object using numpy 1.7 experimental datetime API:

seconds = dt / np.timedelta64(1, 's') 
like image 114
jfs Avatar answered Sep 28 '22 07:09

jfs