Pandas date_range with specific time ranges
I am trying to use pd.date_range()
to create DatetimeIndex
that spans several days with a frequency of seconds. However, the time range for each day must be limited between 05:00:00 and 22:00:00
Something like strings (doesn't work of course):
times_c = pd.date_range(start="2015-01-01",end="2015-01-10",freq="S")
mask_c = ((times_c.time < dt.datetime.strptime("22:00:00", "%H:%M:%S")) | (times_c.time > dt.datetime.strptime("05:00:00","%H:%M:%S")))
times_c = times_c[mask_c]
+3
source to share
3 answers