我想从目标中减去第一个响应,如果输出小于目标,则必须在数据帧的新列中添加“ INSLA”。我收到一个错误,因为在'int'和'str'的实例之间不支持'<'。如何将它们都更改为整数值?
我尝试过使用代码
tickets ['SLA'] = np.where(tickets ['First Response Time(HH:MM:SS)'] 如果第一个响应小于目标或“ OSLA”,则预期输出为“ INSLA” 实际结果是: 回溯(最近通话最近):
文件“ C:\ Users \ Kittu \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ pandas \ core \ ops.py”,行1735,在包装器中 文件“ C:\ Users \ Kittu \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ pandas \ core \ ops.py”,行1625,位于na_op _comp_method_OBJECT_ARRAY中第1601行的文件“ C:\ Users \ Kittu \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ pandas \ core \ ops.py” pandas._libs.ops.vec_compare中的文件“ pandas_libs \ ops.pyx”,第164行
TypeError:“ int”和“ str”的实例之间不支持“ <” report = pd.read_excel('9999.xlsx',index_col=0)
report['Requester'] = report['Requester'].str.replace(" ","") # removes
space from requester columns
report['Requester']= report['Requester'].str.lower() # converts names to
lowercase
df = pd.DataFrame(report)
tickets['Target'] = np.where(tickets['Priority'] =="High" ,'00:25:00',
np.where(tickets['Priority'] == "Medium",'00:30:00',
np.where(tickets['Priority'] == "Normal",'00:30:00',
np.where(tickets['Priority']== "Low",'00:30:00',
np.where(tickets['Priority'] == "Critical",
'00:10:00',tickets['Priority'])))))
tickets['SLA'] = np.where(tickets['First Response Time (HH:MM:SS)']<
tickets['Target'],"INSLA","OSLA")
tickets['SLA'] = np.where(tickets['First Response Time (HH:MM:SS)']< tickets['Target'],"INSLA","OSLA")
res_values = na_op(self.values, other.values)
result = _comp_method_OBJECT_ARRAY(op, x, y)
result = libops.vec_compare(x, y, op)
答案 0 :(得分:1)
在比较日期之前,您必须将列转换为日期时间类型:
tickets['First Response Time (HH:MM:SS)'] = pd.to_datetime(tickets['First Response Time (HH:MM:SS)'], format='%H:%M:%S')
tickets['Target'] = pd.to_datetime(tickets['Target'], format='%H:%M:%S')
(这里我假设Target
列与First Response Time (HH:MM:SS)
的格式相同)