I want to create a date array with arbitrary increments
#Every 3 months
np.arange('2000-01', '2002-02',np.timedelta64(3,'M'), dtype='datetime64')
# ['2000-01' '2000-04' '2000-07' '2000-10' '2001-01' '2001-04' '2001-07' '2001-10' '2002-01']
#Every 2 years
np.arange('2010', '2018',np.timedelta64(2,'Y'), dtype='datetime64')
# ['2010' '2012' '2014' '2016']
#1 minute increments
np.arange('2000-01-01 10:00:00', '2000-01-01 10:05:00',np.timedelta64(1,'m'), dtype='datetime64')
#['2000-01-01T10:00:00' '2000-01-01T10:01:00' '2000-01-01T10:02:00' '2000-01-01T10:03:00' '2000-01-01T10:04:00']
#bonus# '2010'Even if you specify only, it actually has a fine value
np.datetime64('2010')==np.datetime64('2010-01-01 00:00:00') # True
np.datetime64('2010')==np.datetime64('2010-01-01 00:00:01') # False
It seems easier to use if you get used to numpy's datetime
https://numpy.org/devdocs/reference/arrays.datetime.html
Recommended Posts