0

I have df

ID     url     code
111    vk.com   1
111    twitter.com   1
222    facebook.com   1
222    vk.com    1
222    avito.ru   3

Desire output:

ID     url     code
111    vk.com   1
222    facebook.com   1
222    avito.ru     3

I need to delete string, if previous code is equal to this string and ID is equal to this string.

1 Answer 1

2

You can use drop_duplicates() and specify a subset of columns to use.

df.drop_duplicates(['ID', 'code'], keep='first')

This will only consider the ID and code column and will keep the first occurrence, removing the other duplicates.

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.