请问如何生成时间列表?
用range(1,10)可以成生1-10之间的数字,请问如何生成9:00-10:00之间的分钟,比如 import pandas as pddata=pd.date_range(start='09:01',end='09:30',freq='min')
print(data)
DatetimeIndex(['2020-09-06 09:01:00', '2020-09-06 09:02:00',
'2020-09-06 09:03:00', '2020-09-06 09:04:00',
'2020-09-06 09:05:00', '2020-09-06 09:06:00',
'2020-09-06 09:07:00', '2020-09-06 09:08:00',
'2020-09-06 09:09:00', '2020-09-06 09:10:00',
'2020-09-06 09:11:00', '2020-09-06 09:12:00',
'2020-09-06 09:13:00', '2020-09-06 09:14:00',
'2020-09-06 09:15:00', '2020-09-06 09:16:00',
'2020-09-06 09:17:00', '2020-09-06 09:18:00',
'2020-09-06 09:19:00', '2020-09-06 09:20:00',
'2020-09-06 09:21:00', '2020-09-06 09:22:00',
'2020-09-06 09:23:00', '2020-09-06 09:24:00',
'2020-09-06 09:25:00', '2020-09-06 09:26:00',
'2020-09-06 09:27:00', '2020-09-06 09:28:00',
'2020-09-06 09:29:00', '2020-09-06 09:30:00'],
dtype='datetime64', freq='T') import time
start = '2020-08-30 09:50:00'
end = '2020-08-30 10:00:00'
start_timestamp = time.mktime(time.strptime(start,"%Y-%m-%d %H:%M:%S"))
end_timestamp = time.mktime(time.strptime(end,"%Y-%m-%d %H:%M:%S"))
a = map(lambda x:time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(x)),range(int(start_timestamp),int(end_timestamp),60))
print(list(a))
#['2020-08-30 09:50:00', '2020-08-30 09:51:00', '2020-08-30 09:52:00', '2020-08-30 09:53:00', '2020-08-30 09:54:00', '2020-08-30 09:55:00', '2020-08-30 09:56:00', '2020-08-30 09:57:00', '2020-08-30 09:58:00', '2020-08-30 09:59:00']
本帖最后由 Cool_Breeze 于 2020-9-6 19:15 编辑
for i in range(100):
print('{:02}:{:02}'.format(9 + i // 60, i%60))
09:00
09:01
09:02
09:03
页:
[1]