Menu Close

How to remove Python Pandas rows with duplicate indices?

To remove Python Pandas rows with duplicate indices, we call index.duplicated with negation.

For instance, we write

df3 = df3[~df3.index.duplicated(keep='first')]

to get the duplicated indexes of the df3 data frame with

df3.index.duplicated

And then we negate that to return the unique rows.

Posted in Python, Python Answers