How to convert numpy.timedelta64 to minutes

I have a date column in a Pandas DataFrame and I would like to convert it to minutes or seconds.

For example: I want to convert 00:27:00 to 27 minutes.

 example = data['duration'][0] example 

result: numpy.timedelta64(1620000000000,'ns')

What is the best way to achieve this?

+5
source share
1 answer

Use array.astype() to safely convert array type:

 >>> import numpy as np >>> a = np.timedelta64(1620000000000,'ns') >>> a.astype('timedelta64[m]') numpy.timedelta64(27,'m') 
+10
source

Source: https://habr.com/ru/post/1205516/


All Articles