0
0
Pandasdata~10 mins

duplicated() for finding 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 find duplicate rows in the DataFrame df.

Pandas
duplicates = df.[1]()
Drag options to blanks, or click blank then click option'
Aduplicated
Bfillna
Cisnull
Ddropna
Attempts:
3 left
💡 Hint
Common Mistakes
Using dropna() instead of duplicated()
Using isnull() which checks for missing values
2fill in blank
medium

Complete the code to find duplicate rows in df based only on the 'Name' column.

Pandas
duplicates = df.duplicated(subset=[1])
Drag options to blanks, or click blank then click option'
A'Name'
B'Age'
C'Score'
D'City'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name in subset
Not passing the column name as a string
3fill in blank
hard

Fix the error in the code to mark duplicate rows in df, keeping the first occurrence.

Pandas
duplicates = df.duplicated(keep=[1])
Drag options to blanks, or click blank then click option'
A'last'
BFalse
C'first'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean True instead of string 'first'
Using None which is invalid here
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.

Pandas
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition
Using 'word' instead of 'len(word)' for the value
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 letters.

Pandas
result = {{ [1]: [2] for w in words if len(w) [3] 4 }}
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' instead of 'w.upper()' for keys
Using '<' instead of '>' in the condition