小编nut*_*ker的帖子

if语句下的Python-Multiple条件

我正在尝试编写一个函数,该函数将对给定数据集中的商品进行分类(我知道这是非常简单的方式)。

看起来像:

def classifier(x):
    if ('smth' or 'smth' or 'smth') in x:
        return 'class1'
    elif ('smth' or 'smth' or 'smth') in x:
        return 'class2'
Run Code Online (Sandbox Code Playgroud)

因此,问题在于某些条件不起作用。当我尝试分别检查条件时-一切正常。但是在函数中出现了问题。

我将事物功能与pandas apply-method一起使用:

data['classes'] = data['subj'].apply(lambda x: classifier(x))
Run Code Online (Sandbox Code Playgroud)

python string if-statement

1
推荐指数
1
解决办法
74
查看次数

标签 统计

if-statement ×1

python ×1

string ×1