我有一个(TimeSeries 数据)数据框,它看起来像这样:
A1 A2 ... Z1 Z2
2019-06-17 00:00:01 NaN NaN ... NaN NaN
2019-06-17 00:01:59 NaN NaN ... NaN NaN
2019-06-17 00:02:29 NaN NaN ... NaN NaN
... ... ... ... ...
2020-06-17 23:55:01 NaN NaN ... NaN NaN
2020-06-17 23:58:45 NaN NaN ... NaN NaN
2020-06-17 23:59:59 NaN NaN ... NaN NaN
问题:
人们需要按白天(00:00:00)进行选择,因为秒数也可以达到 59,因此需要保持灵活性。
我如何提取给定两个时间值之间的索引(例如 15:00:00、24:00:00)但是:仅在特定的日期范围内(例如星期一至星期四)?
(这就是我提取范围值的方式:)
timeRangesString = "Mon,Thur,15:00,24:00" #<== the input
rangeIndices = pd.Index()
# time ranges:
start_time = time.strptime( timeRangesString.split(",")[0], "%H:%M:%S")#.dt.strftime("%H:%M", '%H:%M:%S')
if timeRangesString.split(",")[1]=="24:00":
end_time = pd.to_datetime("23:59:59", format="%H:%M:%S")
else:
end_time = time.strptime( timeRangesString.split(",")[1], "%H:%M")#.dt.strftime("%H:%M",' %H:%M:%S')
# day ranges:
start_dayint = time.strptime( timeRangesString.split(",")[2], "%a").tm_wday
end_dayint = time.strptime( timeRangesString.split(",")[3], "%a").tm_wday
# ==> start_time == 15:00:00
# ==> end_time == 23:59:59
# ==> start_dayint == 0
# ==> end_dayint == 3
如何将范围内的索引提取到“rangeIndices”中?
一只名叫tom的猫
相关分类