简体   繁体   English

如何检查 pandas 列中的字符串列表的元素是否存在于另一列中

[英]How to check if elements of a list of strings in a pandas column are present in another column

I have a pandas data frame (showing values of one of the rows) as below.我有一个 pandas 数据框(显示其中一行的值),如下所示。 In the annotation column, I have a list of strings which I want to check in the note_sentence column which contains sentences.在注释列中,我有一个字符串列表,我想在包含句子的 note_sentence 列中检查这些字符串。

I used the below code to check the existence but it is unable to capture the existence of strings in the sentences.我使用下面的代码来检查是否存在,但它无法捕获句子中字符串的存在。

df_feature_case_notes['Exists'] = df_feature_case_notes.apply(lambda x: 'Yes' if x['annotation'] in x['note_sentence'] else 'No',axis=1)

How can I fix my code?如何修复我的代码?

在此处输入图像描述

在此处输入图像描述

okay try this好吧试试这个

df_feature_case_notes['Exists'] = [x[0] in x[1] for x in zip(df_feature_case_notes["annotation"], df_feature_case_notes["annotation"])]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查一个pandas列中列表中的所有元素是否存在于另一个pandas列中 - How to check if all the elements in list in one pandas column are present in another pandas column 如何检查列表中的所有元素是否都存在于 pandas 列中 - How to check if all the elements in list are present in pandas column 如何检查 dataframe pandas 中是否不存在列列表 - how to check if a list of column in not present in a dataframe pandas 检查列表的一个或多个元素是否存在于 Pandas 列中 - Check if one or more elements of a list are present in Pandas column 检查具有列表值的列的元素是否存在于另一个列表中 - Check whether the elements of a column with list values are present in another list 如何从熊猫的列中删除列表中的字符串 - How to remove strings present in a list from a column in pandas 将字符串保留在 pandas 的列中的列表中 - Keep strings present in a list from a column in pandas Pandas:如何检查数据框列中的任何列表是否存在于另一个数据帧的范围内? - Pandas: How to check if any of a list in a dataframe column is present in a range in another dataframe? dataframe 的列中存在的子集字符串,具体取决于另一列的值 - Pandas - Subsetting strings present in a column of a dataframe, depending on value of another column - Pandas 检查熊猫列值是否存在于另一个熊猫列(列表)中 - Checking if a pandas column value is present in another pandas column (list)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM