w3resource

Pandas Practice Set-1: Count the duplicate rows of diamonds DataFrame


65. Count Duplicate Rows in Diamonds DataFrame

Write a Pandas program to count the duplicate rows of diamonds DataFrame.

Sample Solution:

Python Code:

import pandas as pd
diamonds = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/diamonds.csv')
print("Original Dataframe:")
print(diamonds.shape)
print("\nDuplicate rows of diamonds DataFrame:")
print(diamonds.duplicated().sum())

Sample Output:

Original Dataframe:
(53940, 10)

Duplicate rows of diamonds DataFrame:
146

For more Practice: Solve these Related Problems:

  • Write a Pandas program to count the number of duplicate rows in the diamonds DataFrame using duplicated() and sum().
  • Write a Pandas program to identify and print all duplicate rows in the diamonds DataFrame and then count them.
  • Write a Pandas program to remove duplicate rows from the diamonds DataFrame and compare the row count before and after removal.
  • Write a Pandas program to generate a summary report that shows the total count of duplicate rows in the diamonds DataFrame.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to read the diamonds DataFrame and detect duplicate color.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.