how can i work with numpytimedelta64 outside of nakbonumpy?

When working with datetime64 dtype arrays, tolist() or item() do a good job of converting the array to base Python objects. Let’s try that with your timedelta:

In [174]: x=np.timedelta64(-2700000000000,'ns')
In [175]: x.item()
Out[175]: -2700000000000

Not quite what we want. But if I first convert it to minutes:

In [176]: x.astype('timedelta64[m]')
Out[176]: numpy.timedelta64(-45,'m')
In [177]: x.astype('timedelta64[m]').item()
Out[177]: datetime.timedelta(days=-1, seconds=83700)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top