yearmonthday = pd.date_range("2020-07-01","2020-12-31",freq="D").strftime("%Y%m%d").to_list()
month = pd.date_range("2020-07-01","2020-12-31", freq="M" ). strftime("%Y%m") .to_list()
day = pd.date_range("2020-07-01","2020-12-31",freq="D").strftime("%d").to_list()
import datetimedef datelist(start, end):start_date = datetime.date(*start)
end_date = datetime.date(*end)
result = []
curr_date = start_date
while curr_date != end_date:
result.append("%04d%02d%02d" % (curr_date.year, curr_date.month, curr_date.day))
curr_date += datetime.timedelta(1)
result.append("%04d%02d%02d" % (curr_date.year, curr_date.month, curr_date.day))
return resultif __name__ == "__main__":
print datelist((2014, 7, 28), (2014, 8, 3))
Python 中有多种用于处理时间序列的库,具体的参数取决于你使用的库。例如,使用 Pandas 时间序列的创建可以使用的参数有:
- start: 起始时间
- end: 结束时间
- periods: 整数,表示生成的时间点的数量
- freq: 时间频率,例如 'D' 表示每天
- tz: 时区
- normalize: 布尔值,表示是否将时间设置为午夜
- name: 时间序列的名称
同样,其他时间序列库也有自己的参数设置。