Apologies if this is an easy one but I can’t see anything in the numpy
documentation. I have a datetime64
and I’d like to find out which day of the week it is.
Unlike python datetime
, datetime64
doesn’t seem to have a .weekday()
function. However it does have a busday_offset()
function, which implies it must know behind-the-scenes what day of the week a given date is. Any help greatly appreciated.
Advertisement
Answer
I think you could do in this way:
JavaScript
x
7
1
import numpy as np
2
import datetime
3
t = '2018-09-19'
4
t = np.datetime64(t)
5
day = t.astype(datetime.datetime).isoweekday()
6
print day
7
Output:
JavaScript
1
2
1
3
2