How to count duplicates in Pandas Dataframe? Improve Improve Like Article Like Save Share Report 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 are to be found will be passed as the value of the index parameter. The value of aggfunc will be ‘size’. # importing the module import pandas as pd # creating the DataFrame df = pd.DataFrame({'Name' : ['Mukul', 'Rohan', 'Mayank', 'Sundar', 'Aakash'], 'Course' : ['BCA', 'BBA', 'BCA', 'MBA', 'BBA'], 'Location' : ['Saharanpur', 'Meerut', 'Agra', 'Saharanpur', 'Meerut']}) # counting the duplicates dups = df.pivot_table(index = ['Course'], aggfunc ='size') # displaying the duplicate Series print(dups) Output : Across multiple columns : We will be using the pivot_table() function to count the duplicates across multiple columns. The columns in which the duplicates are to be found will be passed as the value of the index parameter as a list. The value of aggfunc will be ‘size’. # importing the module import pandas as pd # creating the DataFrame df = pd.DataFrame({'Name' : ['Mukul', 'Rohan', 'Mayank', 'Sundar', 'Aakash'], 'Course' : ['BCA', 'BBA', 'BCA', 'MBA', 'BBA'], 'Location' : ['Saharanpur', 'Meerut', 'Agra', 'Saharanpur', 'Meerut']}) # counting the duplicates dups = df.pivot_table(index = ['Course', 'Location'], aggfunc ='size') # displaying the duplicate Series print(dups) Output Last Updated : 28 Jul, 2020 Like Article Save Article Previous Get column index from column name of a given Pandas DataFrame Next Python - tensorflow.IndexedSlices.op Attribute Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Delete duplicates in a Pandas Dataframe based on two columns Difference Between Spark DataFrame and Pandas DataFrame Pandas Dataframe.to_numpy() - Convert dataframe to Numpy array Convert given Pandas series into a dataframe with its index as another column on the dataframe How to Convert Wide Dataframe to Tidy Dataframe with Pandas stack()? Replace values of a DataFrame with the value of another DataFrame in Pandas Converting Pandas Dataframe To Dask Dataframe Pandas Dataframe rank() | Rank DataFrame Entries Pandas DataFrame to_dict() Method | Convert DataFrame to Dictionary Pandas DataFrame assign() Method | Create new Columns in DataFrame Like mukulsomukesh Follow Article Tags : Python pandas-dataFrame Python-pandas Python Practice Tags : python