简体   繁体   English

使用 python numpy 按月递增日期

[英]increment date by month using python numpy

I know there are some post regarding this matter however I want to keep my current format since to me it is most readable.我知道有一些关于这个问题的帖子,但是我想保留我目前的格式,因为对我来说它是最易读的。

dates = [str(date) for date in np.array("2019-06-14", dtype=np.datetime64) + np.arange(14)]

This creates list of dates which increments by day, how can I increase by months?这会创建按天递增的日期列表,如何按月递增?

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]')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM