A. AttributeError: 'DataFrame' object has no attribute 'duplicate'; fix by using df.duplicated()
B. SyntaxError: missing parentheses; fix by adding () after duplicate
C. TypeError: duplicate() requires arguments; fix by passing columns
D. No error; code runs fine
Solution
Step 1: Identify the error type
The error is AttributeError because duplicate() is not a valid pandas method.
Step 2: Correct the method name
The correct method to detect duplicates is duplicated() with a 'd' at the end.
Final Answer:
AttributeError: 'DataFrame' object has no attribute 'duplicate'; fix by using df.duplicated() -> Option A
Quick Check:
Use duplicated(), not duplicate() [OK]
Hint: Check method spelling: duplicated() not duplicate() [OK]
Common Mistakes:
Using duplicate() instead of duplicated()
Assuming no error occurs
Trying to pass arguments to duplicate()
5. You have a DataFrame with columns ['ID', 'Name', 'Score']. Some rows have the same ID but different Score. You want to keep only the first occurrence of each ID and remove duplicates based on ID only. Which code correctly does this?
hard
A. df.drop_duplicates(subset=['ID'], keep='first')
B. df.drop_duplicates(keep='first')
C. df.duplicated(subset=['ID'], keep='first')
D. df.drop_duplicates(subset=['Score'], keep='last')
Solution
Step 1: Understand the goal
We want to remove duplicates based on ID only, keeping the first occurrence.
Step 2: Choose correct method and parameters
drop_duplicates() removes duplicates; subset=['ID'] limits check to ID column; keep='first' keeps first occurrence.
Step 3: Evaluate options
df.drop_duplicates(subset=['ID'], keep='first') matches the requirement. df.drop_duplicates(keep='first') checks all columns, not just ID. df.duplicated(subset=['ID'], keep='first') returns boolean Series, not DataFrame. df.drop_duplicates(subset=['Score'], keep='last') removes duplicates by Score, not ID.
Final Answer:
df.drop_duplicates(subset=['ID'], keep='first') -> Option A
Quick Check:
Drop duplicates by ID, keep first [OK]
Hint: Use subset to specify columns for duplicate check [OK]
Common Mistakes:
Not using subset to limit columns
Using duplicated() instead of drop_duplicates() to remove rows
Keeping last instead of first occurrence
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.