我知道有一些关于此事的帖子,但是我想保留当前格式,因为对我而言,它最易读。
dates = [str(date) for date in np.array("2019-06-14", dtype=np.datetime64) + np.arange(14)]
这会创建日期列表,该列表每天增加,如何增加几个月?
答案 0 :(得分:0)
In [481]: np.arange(0,10, dtype='datetime64[M]')
Out[481]:
array(['1970-01', '1970-02', '1970-03', '1970-04', '1970-05', '1970-06',
'1970-07', '1970-08', '1970-09', '1970-10'], dtype='datetime64[M]')
In [482]: _.astype('datetime64[D]')
Out[482]:
array(['1970-01-01', '1970-02-01', '1970-03-01', '1970-04-01',
'1970-05-01', '1970-06-01', '1970-07-01', '1970-08-01',
'1970-09-01', '1970-10-01'], dtype='datetime64[D]')
In [511]: np.arange('2019-06-01',6, dtype='datetime64[M]')+np.timedelta64(13,'D'
...: )
Out[511]:
array(['2019-06-14', '2019-07-14', '2019-08-14', '2019-09-14',
'2019-10-14', '2019-11-14'], dtype='datetime64[D]')