Back to Practice
#0119

Flag Duplicate Rows by Key

EasyPandas15 min10 XP

Problem

Given a DataFrame and list of key columns, return a copy with is_duplicate True for rows after the first occurrence of each key.

Why This Matters

Duplicate checks are a first-line data quality habit before analysis or training.

Function Signature

def flag_duplicates(df, keys):

Examples

Example 1
Inputids [1,1,2]
OutputFalse, True, False

Only the second row with id 1 is marked duplicate.

Constraints

  • Return the requested value exactly.
  • Handle the stated edge cases.
  • Keep the solution readable.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputids [1,1,2]
ExpectedFalse, True, False

Only the second row with id 1 is marked duplicate.

Hidden Test Categories
multiple key columnsno duplicatesall duplicates after first