I have two DF that looks like this
xx = pd.DataFrame(np.array([[1, 2, 3], [4, 2,1], [7, 2, 9]]),
columns=['a', 'b', 'c'])
yy = pd.DataFrame(np.array([[1, 8, 3,6], [4, 5, 5,2], [7, 2, 9,5]]),
columns=['aa', 'bb', 'cc','dd'])
I have defined a simple function and applied it to df yy
def match_logic(row):
if row['aa'] == 5:
return 'OK'
if row['bb'] == 5:
return 'OK'
if row['cc'] == 5:
return 'OK'
if row['dd'] ==5:
return 'OK'
else:
return 'NO'
yy['extra'] = yy.apply(lambda row: match_logic(row), axis=1)
table yy now looks like this
I have created a new_df based on a simple logic below
new2 = (yy.aa.isin(xx.a) & yy.bb.isin(xx.b))
new_df = yy[new2]
I am wondering if its possible to re-write the logic to include an 'OR' operator that also checks the 'extra' column and includes any row that has the value 'OK' something like the below code (which I know is incorrect)
new2 = (yy.aa.isin(xx.a) & yy.bb.isin(xx.b) or yy.extra == 'OK')
So that New_df looks like this
aa bb cc dd extra
4 5 5 2 OK
7 2 9 5 OK