1

I have a data frame

 index  col1  col2 col3
     0     1     3    5
     1    12     7   21
  ...    ...   ...  ...

I want to delete some rows, with the criteria being that the values in col1 and col2 show up in a certain list. Let the list be [(12,7),(100,34),...]. In this case, the row with index 1 would be deleted.

1 Answer 1

3

Use Index.isin for test MultiIndex created by both columns by DataFrame.set_index, invert mask by ~ and filter in boolean indexing:

L = [(12,7),(100,34)]

df = df[~df.set_index(['col1','col2']).index.isin(L)]
print (df)
   col1  col2  col3
0     1     3     5
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.