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.
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.
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'.
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.
To get number of seconds from numpy.timedelta64()
object using numpy
1.7 experimental datetime API:
seconds = dt / np.timedelta64(1, 's')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With