I have the following dataframe:
df = pd.DataFrame([['50030', '36 @ 3159 W/270, LWD[GR,RES,PWD] @ 4015', '3159'],
['50030', '36 @ 3159 W/270, LWD[GR,RES,PWD] @ 4015', '3994'],
['50030', '36 @ 3159 W/270, LWD[GR,RES,PWD] @ 4015', '5401'],
['50030', '26 @ 3994, LWD[GR,RES,PWD] @ 5430, 20 @ 5401', '3159'],
['50030', '26 @ 3994, LWD[GR,RES,PWD] @ 5430, 20 @ 5401', '3994'],
['50030', '26 @ 3994, LWD[GR,RES,PWD] @ 5430, 20 @ 5401', '5401']],
columns = ["WKEY", "Description", "DEPTH"])
I want to compare the value in the DEPTH column (which is a string value) to the string in the Description column only for the same row. A new column called "Compare" would have a yes or no depending on if it exists.
Based on this post: python pandas - Check if partial string in column exists in other column, I tried this code:
df['Compare'] = df['DEPTH'].apply(lambda x: 'Yes' if df['Description'].str.contains(x).any() else 'No')
However, it returns all rows with Yes:
It should be Yes, No, No, No, Yes, Yes.
The ultimate plan is to delete all rows which do not have the value in the DEPTH column also listed somewhere in the Description column in the same row.
I feel like I'm one step away from getting this to work, so any direction would be appreciated.
Thanks!

