我想每2.5分钟创建一个样本的时间范围,我知道样本的开始时间和数量。
以下是从给定日期开始,将1000个时间戳分隔5分钟的代码:
date = pandas.date_range(datetime(2015, 12, 25, hour=12, minute=0),
periods=1000, freq='5min')
如何指定2分30秒的频率?
答案 0 :(得分:2)
将2min30S
作为freq
参数传递:
In [9]:
pandas.date_range(datetime(2015, 12, 25, hour=12, minute=0), periods=1000, freq='2min30S')
Out[9]:
DatetimeIndex(['2015-12-25 12:00:00', '2015-12-25 12:02:30',
'2015-12-25 12:05:00', '2015-12-25 12:07:30',
'2015-12-25 12:10:00', '2015-12-25 12:12:30',
'2015-12-25 12:15:00', '2015-12-25 12:17:30',
'2015-12-25 12:20:00', '2015-12-25 12:22:30',
...
'2015-12-27 05:15:00', '2015-12-27 05:17:30',
'2015-12-27 05:20:00', '2015-12-27 05:22:30',
'2015-12-27 05:25:00', '2015-12-27 05:27:30',
'2015-12-27 05:30:00', '2015-12-27 05:32:30',
'2015-12-27 05:35:00', '2015-12-27 05:37:30'],
dtype='datetime64[ns]', length=1000, freq='150S')
或150S
也可以使用