import pandas as pd
def get_date_list(begin_date,end_date,freq):
    date_list = [x.strftime('%Y-%m') for x in list(pd.date_range(start=begin_date, end=end_date,freq = freq))]
    return date_list
get_date_list('2021','2022','m')
['2021-01',
 '2021-02',
 '2021-03',
 '2021-04',
 '2021-05',
 '2021-06',
'2021-07',
 '2021-08',
 '2021-09',
 '2021-10',
 '2021-11',
 '2021-12']

freq = d,m,y 分别代表按照天,月,年时间段生成时间。

Logo

GitCode AI社区是一款由 GitCode 团队打造的智能助手,AI大模型社区、提供国内外头部大模型及数据集服务。

更多推荐