How to delete duplicate rows in Pandas

In this article, you’ll learn how to delete duplicate rows in Pandas. The given example with the solution will help you to delete duplicate rows of Pandas DataFrame.

Example: Delete Duplicate Rows

# Import the Pandas library as pd
import pandas as pd

# Create a DataFrame
df = pd.DataFrame({'col_1': [10, 88, 88, 9],
                    'col_2': [10, 88, 88, 8],
                    'col_3': [19, 88, 88, 2]})

# Display the DataFrame
print(df)

# Delete the Duplicate Rows
df = df.drop_duplicates()

# Display the Modified DataFrame
print(df)

Output:

   col_1  col_2  col_3
0     10     10     19
1     88     88     88
2     88     88     88
3      9      8      2
   col_1  col_2  col_3
0     10     10     19
1     88     88     88
3      9      8      2

If you want to learn Pandas, I recommend this book and free resource.

Leave a Comment

Your email address will not be published.