【发布时间】:2021-05-06 11:57:23
【问题描述】:
我从现有数据帧中获得了 DateTimeIndex
time=df.index[19:]
在一定的时间范围内,我想创造一定的价值
list=[]
for i in range(0,len(time)):
#if time[i] in the range of '2020-06-25 11:53:05' to '2020-06-25 12:23:05': this part I don't know how
correct.append(1)
else:
correct.append(0)
所以结果应该如下所示,在某个时间范围内,该值将为 1,而在其他时间范围内,它只是 0。
list= [0,0,0,0,1,1,1,0,0,0,0]
我不知道如何使用这种类型的数据索引,并且我已经搜索了多个工具来使用 DateTimeIndex,但找不到与解决我的案例相关的内容。并且范围应该与 DateTimeIndex (以秒为单位)精确,还是粗略的猜测仍然有效?例如,“2020-06-25 11:00:00”到“2020-06-25 12:00:00”
非常感谢您的帮助!自学并不容易,有时我什至不知道该找什么关键字。
【问题讨论】:
标签: pandas numpy datetimeindex