Skip to content Skip to sidebar Skip to footer

Calculate If Date Value Occurs Between Two Different Times Python Pandas

I am trying to create a new column to determine if a row value is 'between business hours'. To do this I am trying to use the between time function. I dont need to use it if there

Solution 1:

You do not need set the index

df.Date.dt.strftime('%H:%M').between(df.StartHour,df.EndHour)
Out[297]: 
0False1True2True3True4False5True6True7True8False
dtype: bool

Update

l=[df.loc[[y],:].index.indexer_between_time(df.loc[y,'StartHour'],df.loc[y,'EndHour'])==0foryindf.index]df['New']=ldf.New=df.New.str[0].fillna(False)dfEndHourStartHourStation_IDNewDate2016-11-17 05:01:45   10:0016:00ATrue2011-01-04 16:34:00   10:0016:00ATrue2011-01-05 09:25:45   10:0016:00ATrue2011-01-10 12:00:45   10:0016:00AFalse2011-01-14 07:05:45   10:0016:00BTrue2011-01-15 10:19:00   10:0016:00BFalse2011-01-17 13:59:45   10:0016:00BFalse2011-01-19 18:39:45   10:0016:00BTrue2011-01-22 06:19:45   10:0016:00BTrue

Post a Comment for "Calculate If Date Value Occurs Between Two Different Times Python Pandas"