0
0
Pandasdata~10 mins

Duplicates on specific columns 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 based 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'Salary'
D['City']
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a list for subset.
Checking duplicates without specifying subset.
2fill in blank
medium

Complete the code to drop duplicate rows based on 'Name' and 'City' columns, keeping the first occurrence.

Pandas
df_unique = df.drop_duplicates(subset=[1], keep='first')
Drag options to blanks, or click blank then click option'
A'Name'
B['Name', 'City']
C'City'
D['Age', 'Salary']
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single string instead of a list for subset.
Not specifying the keep parameter.
3fill in blank
hard

Fix the error in the code to find duplicates based on 'Age' column.

Pandas
duplicates = df.duplicated(subset=[1])
Drag options to blanks, or click blank then click option'
AAge
B'Age'
C'age'
D['Age']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a list.
Using a variable without quotes.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 characters.

Pandas
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 4
Cword > 4
Dword.length()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word > 4 instead of length comparison.
Using word.length() which is not valid in Python.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 characters.

Pandas
result = [1]: [2] for word in words if [3]
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of uppercase.
Not filtering words by length.