python 按照时间段生成时间列表
import pandas as pddef 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_listget_date_list('
·
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 分别代表按照天,月,年时间段生成时间。
更多推荐



所有评论(0)