我的问题与此类似: How to check whether the content of Column A is contained in Column B using Python DataFrame?
不幸的是,在我的例子中,选择的答案导致了一个非类型错误。你知道吗
我有一个熊猫数据帧,格式如下:
id,text_1,text_2_compare
1,yyy,yy
2,yxy,xx
3,zzy,zy
4,zzy,x
5,xyx,yx
我想比较这些列,看看“text\u 1”中是否包含“text\u 2\u compare”,并创建一个新的指示符。你知道吗
id,text_1,text_2_compare,match
1,yyy,yy,1
2,yxy,xx,0
3,zzy,zy,1
4,zzy,x,0
5,xyx,yx,1
任何提示或技巧(特别是矢量化的实现)将不胜感激!你知道吗
基于@onyanbu的答案。你知道吗
in
可以用来代替re.findall()
输出:
编辑:
实际上,我以为OP需要
text_2_compared
出现在text_1
中的次数,但再看一遍这个问题,似乎OP只需要一个指示变量。因此,使用@gaganso上面所做的v[2] in v[1]
就足够了使用简单列表
相关问题 更多 >
编程相关推荐