(TIL) Numpy: Extract days from timedelta64

less than 1 minute read

To extract the integer value of days from a numpy.timedelta64, you divide it with a timedelta64 of one day:

>>> x = np.timedelta64(2069211000000000, 'ns')
>>> days = x.astype('timedelta64[D]')
>>> days / np.timedelta64(1, 'D')
23

Via StackOverflow.

Tags: ,

Categories:

Updated:

Comments