簡體   English   中英

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

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

我有一個 pandas 數據框(顯示其中一行的值),如下所示。 在注釋列中,我有一個字符串列表,我想在包含句子的 note_sentence 列中檢查這些字符串。

我使用下面的代碼來檢查是否存在,但它無法捕獲句子中字符串的存在。

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

如何修復我的代碼?

在此處輸入圖像描述

在此處輸入圖像描述

好吧試試這個

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM