简体   繁体   中英

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. In the annotation column, I have a list of strings which I want to check in the note_sentence column which contains sentences.

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"])]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM