Categories
Python Answers

How to remove Python Pandas rows with duplicate indices?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *