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

Viewed 32

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?

enter image description here

1 Answers

enter image description here

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