Skip to content
Advertisement

How to delete duplicates pandas

I need to check if there are some duplicates value in one column of a dataframe using Pandas and, if there is any duplicate, delete the entire row. I need to check just the first column.

Example:

JavaScript

What i need is:

JavaScript

I can delete the ‘object’ duplicates with the following code, but I can’t delete the entire row that contains the duplicate as the second column won’t be deleted.

JavaScript

Advertisement

Answer

Select by duplicated mask and negate it

JavaScript

Which gives

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement