0

I have the following dataset (see figure) dataframe

I need to extract all rows from the Results data frame such that Results['Class'] is in Results[Path_x']

(In the specific case, it should only return me the second-to-last line because Results['Class'] is totally contained in Results['Path_x'] in the penultimate case)

I tried the following line of code:

results=results[results['Class'].isin(results['Path_x'])]

However, that line always generates an empty data frame.

0

1 Answer 1

1

You can do

mask = results.apply(lambda x: ['Class'] in results['Path_x'], axis=1)
results= results.loc[mask, :]

See this question: Python Pandas: Check if string in one column is contained in string of another column in the same row

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.