on-internet
← Community

Conditionally dropping duplicate rows

Stack Overflow ·

I have a pandas dataframe that looks as such: header1 header2 header3 val1 1 True val2 2 True val1 1 True val2 2 False and I want to conditionally deduplicate the rows, based upon if the last column is True or not. In the above table I want the output dataframe after drops to look like this: header1 header2 header3 val1 1 True val2 2 True val2 2 False having deduplicated the third row, as it had header 3 set to true, but not the fourth row, as it had header 3 set to false. I haven't yet been able to figure out how to do this, as drop_duplicates doesn't support this explicitly and it's not gene

Comments

Sign in or sign up to comment and upvote.

No comments yet.