我正在尝试创建一个列,如果行值落在时间 09:00 和 17:00 之间,该列将分配 true。
我可以使用轻松选择这些时间between_time
但无法分配新列 aTrue
, False
.
df = df.between_time('9:00', '17:00', include_start=True, include_end=True)
该语句选择适当的行,但我无法为它们分配 True-False 值。
我一直在尝试使用np.where
.
df['day'] = np.where(df.between_time('9:00', '17:00', include_start=True, include_end=True),'True','False')
除了那个np.where
仅适用于布尔表达式。
我这样使用它:
df['day'] = np.where((df['dayTime'] < '09:00') & (df['dayTime'] > '17:00'),'True','False')
但只得到了False returns
,因为一个值不能同时大于 17 和小于 9。
我错过了一个相对简单的步骤,无法弄清楚。帮助。