根据python中的某些条件做一些事情

时间:2018-07-08 20:52:00

标签: python python-3.x numpy

仅当满足某些条件时,我才需要在python中进行操作。

假设我要执行此操作:

data2["Comment"].str.contains("\\berror\\b", case = False,na=False)) 

满足以下条件时

data2['SR Ticket num'].isin(data1['SR Ticket num']) &  ( data1['flag'] != 'yes')

我正在写下面的代码并出现错误

rule5 = (data2["Comment"].str.contains("\\berror\\b", case = False,na=False)) np.where(data2['SR Ticket num'].isin(data1['SR Ticket num']) &  ( data1['flag'] != 'yes')

请提出在满足某些条件时如何执行此操作的建议。我尝试过,但是语法无效。

1 个答案:

答案 0 :(得分:0)

如何满足条件的示例

data1 = {'flag':'no', 'SR Ticket num': 56}
data2 = {"Comment": "berror", "SR Ticket num": 56}

na = None 

if "berror"  in data2["Comment"]:
    # berror found in data2 Comment
    # continue here 
    na = True 
else:
    # berror not found
    # continue here 
    na = False 


if data2['SR Ticket num'] == data1["SR Ticket num"] and data1['flag'] != 'yes':
    # data2 SR Ticket num is equal with data1 SR Ticket num and data1 flag is not set to yes 
    # continue here 
    pass