Check If One String Contains Another Substring In Python
I have a data set which looks something like this. **name** **url** **title** Microsoft asdfgaethgaetgh Microsoft Is a big company Apple aeiurghp
Solution 1:
This can also be used :
criteria = lambda row : row['name'] inrow['title']
df['flag'] = df.apply(criteria, axis =1)
Solution 2:
You can use df['flag'] = True if df.name in df.title else False
The code uses single line if else condition
Solution 3:
isin will work only if you want to search name within list of names. To search for substring use str.contains instead
df.title.str.contains(df.name)
Solution 4:
Sample like this;
ifdf[name] indf[title]:
returntrueSolution 5:
Your code should be like this
df['flag'] = (df.name in df.title)
Post a Comment for "Check If One String Contains Another Substring In Python"