检查一个字符串是否在python中包含另一个子字符串 [英] check if one string contains another substring in python

查看:304
本文介绍了检查一个字符串是否在python中包含另一个子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的数据集.

I have a data set which looks something like this.

**name**       **url**               **title**
Microsoft  asdfgaethgaetgh   Microsoft Is a big company
Apple      aeiurghp          iphone is a Apple product
Google     iailsu            Yahoo, Bing Profit Rises

我想使用一个标志,如果'title'的单元格值中存在'name'的单元格值,则在'True'处使用.否则为假"

I would like to use a flag where 'True' would be if the cell value of 'name' is present in the cell value of 'title'. Otherwise, 'False'

我正在使用类似的东西

df['flag'] = (df.name).isin(df.title)

但这会将所有标志都设置为"False",其中前两个标志应为"True"

But this gives all the flags as 'False', whereaas the first two flags should be 'True'

我该如何处理?

推荐答案

这也可以使用:

criteria = lambda row : row['name'] in row['title']
df['flag'] = df.apply(criteria, axis =1)

这篇关于检查一个字符串是否在python中包含另一个子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆