我试图将1个数据帧列中的单词或stings与同一df中的另一个列进行比较,并只输出匹配单词的第3列。在
input
Col1
the cat crossed a road
the dog barked
the chicken barked
Col2
the cat alligator
some words here
chicken soup
desired result
Col3
the cat
NULL
chicken
这是我所拥有的,只是有一个错误。在
^{pr2}$
错误是
TypeError:字符串索引必须是整数
Tags:
{{than{1>使用{cd2>来匹配}列表
此外,您必须使用
axis=1
才能使其工作:输出:
^{pr2}$如果您想要
NULL
,而不仅仅是一个空值,请使用:输出:
检查
这里不需要使用lambda函数,只需检查每个单词是否包含在同一列的字符串中。zip()函数对于列迭代非常有用。以下是一种方法:
相关问题 更多 >
编程相关推荐