Python函数错误:“<"类型'str'和'int'之间不支持 [英] Python function error : '<' not supported between types 'str' and 'int'
本文介绍了Python函数错误:“<"类型'str'和'int'之间不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从事重复分类项目.我正在计算几天内重复和新邮件之间的时间间隔.我想在此时间间隔上应用一个函数,该函数指出是新邮件还是重复邮件.
I am working on repeats classification project. I am calculating time lapse in between a repeat and fresh mail in days. I want to apply a function on this time lapse which states whether it is a fresh mail or repeat mail.
功能:
days = df['days_difference']
if(days<30):
return 'repeat'
else:
return 'fresh'
我遇到错误:'str'和'int'实例之间不支持
I am getting error: not supported between instances of 'str' and 'int'
"days_difference"列包含整数值和无值.
'days_difference' column contains integer values along with None values.
寻找解决方案!
推荐答案
这基本上意味着您的'days'变量是一个字符串.您不能使用<"将字符串与整数进行比较.试试:
That basically means that your 'days ' variable is a string. You can not compare strings with integers using "<". Try :
...
if(int(days)<30):
...
这篇关于Python函数错误:“<"类型'str'和'int'之间不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文