0
0
Pandasdata~10 mins

Counting duplicates in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to count duplicate rows in the DataFrame.

Pandas
duplicate_count = df.[1]().sum()
Drag options to blanks, or click blank then click option'
Aunique
Bdrop_duplicates
Ccount
Dduplicated
Attempts:
3 left
💡 Hint
Common Mistakes
Using drop_duplicates() which removes duplicates instead of identifying them.
Using count() which counts non-null values, not duplicates.
2fill in blank
medium

Complete the code to count how many duplicate rows exist in the DataFrame.

Pandas
num_duplicates = [1](df[df.duplicated()])
Drag options to blanks, or click blank then click option'
Acount
Bsize
Clen
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() which sums values but the DataFrame rows are not numeric.
Using count() which counts non-null values per column, not rows.
3fill in blank
hard

Fix the error in the code to count duplicate rows correctly.

Pandas
duplicate_rows = df.[1]().sum()
Drag options to blanks, or click blank then click option'
Adrop_duplicates
Bduplicated
Cunique
Dvalue_counts
Attempts:
3 left
💡 Hint
Common Mistakes
Using drop_duplicates() which returns a DataFrame, not booleans.
Using unique() which returns unique rows, not duplicates.
4fill in blank
hard

Fill both blanks to create a dictionary with counts of duplicate rows and unique rows.

Pandas
counts = {'duplicates': df.[1]().sum(), 'unique': len(df.[2]())}
Drag options to blanks, or click blank then click option'
Aduplicated
Bdrop_duplicates
Ccount
Dunique
Attempts:
3 left
💡 Hint
Common Mistakes
Using unique() which returns unique values of a Series, not rows.
Using count() which counts non-null values, not unique rows.
5fill in blank
hard

Fill all three blanks to create a dictionary with counts of duplicate rows, unique rows, and total rows.

Pandas
counts = {'duplicates': df.[1]().sum(), 'unique': len(df.[2]()), 'total': df.[3]
Drag options to blanks, or click blank then click option'
Aduplicated
Bdrop_duplicates
Cshape[0]
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count which counts non-null values per column, not total rows.
Using unique() which is for Series, not DataFrame rows.