Drop Duplicate Values in a Pandas DataFrame Column

Python
Data Preprocessing

 1|  # Will drop any rows that contain duplicate values in the Name column 
 2|  # but will keep the first row that contains a duplicated value
 3|  df.drop_duplicates(subset=['Name'], inplace=True)
 4|  
 5|  # Will drop any rows that contain duplicate values in the Name column 
 6|  # but will keep the last row that contains a duplicated value
 7|  df.drop_duplicates(subset=['Name'], keep='last', inplace=True)
 8|  
 9|  # Will drop any rows that contain duplicate values in the Name column
10|  df.drop_duplicates(subset=['Name'], keep=False, inplace=True)
1 Upvote
Did you find this snippet useful?

Sign up to bookmark this in your snippet library

Normalize Windowed Time Series
Python
Data Preprocessing

Scaler | Normalize | Scale | Min-max

4
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3