I would like to ask your help with an "if statement" inside a function that I am using to aggregate some data in a dataframe. With this function I wanted to check if any of several strings are in other string in one column of my dataframe to return an specific value and the matching string.
This is what I have so far and it does what I need. For example, if "f" and "k" are in my string ("fk"), once I apply my function on this row (find_string("fk")), my function will return "success". Additionally I would also like to have the string that was found in the list, in this case 'f'. Something like "success" + "f"
def find_string(b):
if "a" in b or "c" in b or "d" in b or "f" in b:
return "success" ## here I want to get the matching string
Any suggestion?
I am using python 2.7.13 with pandas library.
pandasthat are much faster than normal loops