• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
October 25, 2022 |2.5K Views

How to Remove Duplicate Rows in Pandas Dataframe

  Share  1 Like
Description
Discussion

Pandas drop_duplicates() method helps in removing duplicates from the Pandas Dataframe In Python.

Syntax of df.drop_duplicates()

Syntax: DataFrame.drop_duplicates(subset=None, keep=’first’, inplace=False)

Parameters:

  • subset: Subset takes a column or list of column label. It’s default value is none. After passing columns, it will consider them only for duplicates.
  • keep: keep is to control how to consider duplicate value. It has only three distinct value and default is ‘first’.
    • If ‘first‘, it considers first value as unique and rest of the same values as duplicate.
    • If ‘last‘, it considers last value as unique and rest of the same values as duplicate.
    • If False, it consider all of the same values as duplicates
  • inplace: Boolean values, removes rows with duplicates if True.

Return type: DataFrame with removed duplicate rows depending on Arguments passed. 

 

Related Article :  https://www.geeksforgeeks.org/python-pandas-dataframe-drop_duplicates/