Pandas Find Duplicate Rows Last Updated : 17 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Most simple way to find duplicate rows in DataFrame is by using the duplicated() method. This method returns a boolean Series indicating whether each row is a duplicate of a previous row. Python import pandas as pd data = {'Name': ['John', 'Alice', 'Bob', 'Eve', 'John', 'Charlie'], 'Age': [25, 30, 22, 35, 25, 28], 'Gender': ['Male', 'Female', 'Male', 'Female', 'Male', 'Male'], 'Salary': [50000, 55000, 40000, 70000, 50000, 48000]} df = pd.DataFrame(data) # Find duplicate rows duplicates = df[df.duplicated()] print(duplicates) Output Name Age Gender Salary 4 John 25 Male 50000 In addition to the this method, there are several other approaches to find out the Duplicate rows in Pandas.1. Identifying Duplicates Based on Specific ColumnsSometimes, you may only want to check for duplicates in specific columns, rather than the entire row. we can use duplicated() with the subset parameter to check for duplicates in specific columns.The subset parameter allows you to specify which columns to consider when looking for duplicates. In this case, we're checking for duplicates based on the Name and Age columns. Python # Find duplicates based on 'Name' and 'Age' columns duplicates_by_columns = df[df.duplicated(subset=['Name', 'Age'])] print(duplicates_by_columns) Output Name Age Gender Salary 4 John 25 Male 50000 2. Removing Duplicate Rows Using drop duplicatesOnce duplicates are identified, you can remove them using the drop_duplicates() method. This method returns a new DataFrame with the duplicate rows removed.The drop_duplicates() method removes all rows that are identical to a previous row. By default, it keeps the first occurrence of each row and drops subsequent duplicates. Python # Remove duplicate rows df_no_duplicates = df.drop_duplicates() print(df_no_duplicates) Output Name Age Gender Salary 0 John 25 Male 50000 1 Alice 30 Female 55000 2 Bob 22 Male 40000 3 Eve 35 Female 70000 5 Charlie 28 Male 48000 Here are some key takeaways: Identify duplicates using duplicated()Find duplicates based on specific columnsRemove duplicate rows with drop_duplicates() Comment More infoAdvertise with us Next Article Pandas Find Duplicate Rows A abhirajksingh Follow Improve Article Tags : Pandas AI-ML-DS Python-pandas Python pandas-basics Similar Reads Python | Pandas Index.duplicated() The Index.duplicated() method in Pandas is a powerful tool for identifying duplicate values within an index. It returns a boolean array where duplicates are marked as True based on the specified criteria and False denotes unique values or the first occurrence of duplicates. This method is especially 5 min read Python | Pandas Index.get_duplicates() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.get_duplicates() function extract duplicated index elements. This functio 2 min read Python | Pandas Index.drop_duplicates() Pandas Index.drop_duplicates() function return Index with duplicate values removed in Python. Syntax of Pandas Index.drop_duplicates() Syntax: Index.drop_duplicates(labels, errors='raise')Â Parameters : keep : {âfirstâ, âlastâ, False} âfirstâ : Drop duplicates except for the first occurrence.(defaul 2 min read Python | Pandas Series.duplicated() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.duplicated() function indicate 2 min read Python | Pandas Index.identical() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.identical() function determine if two Index objects contains the same ele 2 min read How to count duplicates in Pandas Dataframe? Let us see how to count duplicates in a Pandas DataFrame. Our task is to count the number of duplicate entries in a single column and multiple columns. Under a single column : We will be using the pivot_table() function to count the duplicates in a single column. The column in which the duplicates a 2 min read Python | Pandas Series.drop_duplicates() Pandas Series.drop_duplicates() function returns a series object with duplicate values removed from the given series object. Syntax: Series.drop_duplicates(keep='first', inplace=False) Parameter : keep : {âfirstâ, âlastâ, False}, default âfirstâ inplace : If True, performs operation inplace and retu 2 min read Python | Pandas TimedeltaIndex.duplicated Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas TimedeltaIndex.duplicated() function detects duplicate values in the given Time 2 min read Python | Pandas Index.equals() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.equals() function determine if two Index objects contains the same elemen 2 min read Create A Set From A Series In Pandas In Python, a Set is an unordered collection of data types that is iterable, mutable, and has no duplicate elements. The order of elements in a set is undefined though it may contain various elements. The major advantage of using a set, instead of a list, is that it has a highly optimized method for 3 min read Like