如何进行多条件判断list中的值是否在某列里面?
问题:商品标题中如果含有:春、夏这两个字就返回SS,含有秋冬就返回FW,否则返回其他。
使用两种方法:
python:
自定义一个函数进行判断
def season(title):
if "春" in title:
return "SS"
elif "秋" in title:
return "FW"
elif "夏" in title:
return "SS"
elif "冬" in title:
return "FW"
else:
return "其他"
df['季节判断']=df.apply(lambda s:season(s['商品名称']),axis=1)
excel
使用if 和countif相结合
=IF(COUNTIF(D17,"*春*")>0,"SS",IF(COUNTIF(D17,"*冬*")>0,"FW","其他"))