我有一个(TimeSeries 数据)数据框,它看起来像这样: A1 A2 ... Z1 Z22019-06-17 00:00:01 NaN NaN ... NaN NaN2019-06-17 00:01:59 NaN NaN ... NaN NaN2019-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 NaN2020-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 inputrangeIndices = 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_wdayend_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”中?
1 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
IIUC,DataFrame.between_time
并pd.DatetimeIndex.weekday
表现出boolean indexing
df.loc[df.index.weekday < 4].between_time('15:00', '00:00')
添加回答
举报
0/150
提交
取消