'datetime.time'对象没有属性'where'Python

问题描述 投票:0回答:1

我需要检查员工在休息期间是否已经退房。为此,我需要查看是否存在[[time,其中Door NameRDC_OUT-1 在间隔[12:15:00; 14:15:00]

import pandas as pd df_by_date= pd.DataFrame({'Time':['01/02/2019 07:02:07', '01/02/2019 10:16:55', '01/02/2019 12:27:20', '01/02/2019 14:08:58','01/02/2019 15:32:28','01/02/2019 17:38:54'], 'Door Name':['RDC_OUT-1', 'RDC_IN-1','RDC_OUT-1','RDC_IN-1','RDC_OUT-1','RDC_IN-1']}) df_by_date['Time'] = pd.to_datetime(df_by_date['Time']) df_by_date['hours']=pd.to_datetime(df_by_date['Time'], format='%H:%M:%S').apply(lambda x: x.time()) print('hours \n',df_by_date['hours']) out = '12:15:00' inn = '14:15:00' pause=0 for i in range (len(df_by_date)): if (out < str((df_by_date['hours'].iloc[i]).where(df_by_date['Door Name'].iloc[i]=='RDC_IN-1')) < inn) : pause+=1 print('Break outside ') else: print('Break inside')
运行上面的代码时,出现此错误:

if (out < ((df_by_date['hours'].iloc[i]).where(df_by_date['Door Name'].iloc[i]=='RDC_OUT-1')) < inn) :

[AttributeError:'datetime.time'对象没有属性'where']
python-3.x comparison where-clause
1个回答
1
投票
当迭代

DataFrame / Series时,您一次选择一个单元格。

您正在选择的单元格的类型为datetime.time

但是,where仅与完整的[[DataFrame / Series

一起使用,而不是循环使用。

例如,

sub_df = df_by_date['hours'].where(condition)

然后要计数,您可以使用len(sub_df)

© www.soinside.com 2019 - 2024. All rights reserved.