Im trying to check if one of strings in column Name B is found in column Name A by creating new column Name Check:
Current Inputs:
df = pd.DataFrame({"Name A":{"0":"John","1":"Sara","2":"Adam","3":"Ahmed"},
"Name B":{"0":"John, Geroge","1":"Ahemed, Sara","2":"Adam, Nadia","3":"Sara, John"},
"Salary":{"0":100,"1":200,"2":300,"3":400}})
Name A Name B Salary
0 John John, Geroge 100
1 Sara Ahemed, Sara 200
2 Adam Adam, Nadia 300
3 Ahmed Sara, John 400
Excepted Output :
Name A Name B Salary Name Check
0 John John, Geroge 100 True
1 Sara Ahemed, Sara 200 True
2 Adam Adam, Nadia 300 True
3 Ahmed Sara, John 400 False
4 Nadi Sara, Nadia 500 True
5 George Georg, Mo 600 True
What i have tried :
df['Name Check'] = df.apply(lambda x: x['Name B'] in x['Name A'] , axis=1)
But the output is all False, not sure how to convert column Name B to a list and loop through to check one by one if found in column Name A.