字符串搜索功能

巴里·曼利

所以这有效:

idocs[idocs['Message'].str.contains('No sold-to found')]

但这不是:

def msg_logic(msg):
    if msg.str.contains('No sold-to found'):
       return 'No Sold-to'
    else:
       return 'Other'

idocs['Category'] = idocs.apply(lambda x: msg_logic(x['Message']),axis=1)
print(idocs['Category'].unique())    
idocs.head()
拉斐尔·费雷拉
def msg_logic(msg):
    if 'No sold-to found' in msg:
       return 'No Sold-to'
    else:
       return 'Other'

idocs['Category'] = idocs.apply(lambda x: msg_logic(x['Message']),axis=1)
print(idocs['Category'].unique())    
idocs.head()

您的代码无法运行,因为msg在函数中是字符串,没有数据框。

要么

idocs['Category'] = idocs['Message'].apply(lambda x: "No Sold-to" if "No sold-to found" in x else "Other")  

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章