{"id":"code-work-hr-pandas-dedupe-applicants","audience":"hr","category":"coding","track":"coding","technique":"context","title":"Dedupe applicants with pandas, keeping the latest one","free":false,"task":"Write a pandas script that reads applicants.csv and writes applicants_clean.csv with one row per person. People are matched by email, but emails come in with mixed capitals and stray spaces, so lowercase and trim them first. Keep each person's most recent application by applied_on (a date), keep all the original columns, and don't write the index. One code block, at most 12 lines, then under 20 words outside the code.","materialLabel":"Sample of the applicant export (attached to your prompt automatically)","material":"applicants.csv - exported from Hirebee, all open roles (first rows)\n\nname,email,role,applied_on,source\nMaya Chen,maya.chen@mail.example,Office Coordinator,2026-09-14,Job board\nMaya Chen, Maya.Chen@Mail.example ,Office Coordinator,2026-10-02,Referral\nLuis Romero,lromero@post.example,Bookkeeper,2026-10-05,Website\nPriya Shah,priya.s@mail.example,Office Coordinator,2026-08-30,Job board\nPRIYA SHAH,PRIYA.S@MAIL.EXAMPLE,Receptionist,2026-10-11,Job board\nTom Fisher,tfisher@inbox.example,Bookkeeper,2026-10-07,Website\n\nNotes from Gwen (recruiting):\n- Hirebee creates a new row every time someone reapplies.\n- About 1,800 rows this year.\n- Source is sometimes blank for older applications.\n- The hiring managers sort the clean file by role before reading it.\n- Some people apply to two different roles; for now we only want one row per person.\n- Referral bonuses are tracked separately in the payroll system.\n- Last quarter we deleted duplicates by hand, which took most of a Friday.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":12},{"type":"maxProseWords","max":20}],"mistakes":[{"title":"Not mentioning messy emails","why":"The AI dedupes on the raw email, so Maya.Chen@ and maya.chen@ stay as two people.","fix":"Add: \"Lowercase and trim emails before deduping.\"","checks":["r0"]},{"title":"Not saying which row to keep","why":"The AI keeps the first row it sees, which is often the oldest application.","fix":"Add: \"Keep the most recent by applied_on.\"","checks":["r1"]},{"title":"Leaving the output open","why":"The AI writes the index as an extra column or trims columns it thinks you don't need.","fix":"Add: \"Keep all columns, index=False.\"","checks":["r2"]},{"title":"Getting a menu of options","why":"The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself.","fix":"Add: \"Give one script only, in one code block, no alternatives.\"","checks":["codeBlocks","maxCodeLines"]},{"title":"Getting a tutorial","why":"By default the AI explains every part of the code at length, which you then have to scroll past.","fix":"Add: \"After the code, one line under 12 words. Nothing else.\"","checks":["maxProseWords"]}],"promptHints":[{"label":"Normalizes emails","patterns":["lower","trim|strip","spaces","capital"]},{"label":"Says which row to keep","patterns":["most recent","latest","newest","keep=.?last"]},{"label":"Sets the output","patterns":["index=false","no index","all (the )?columns"]},{"label":"Asks for one answer only","patterns":["\\b(one|single|1)\\s+(script|code block|block|version)","only one","no (alternatives|options|other versions)"]},{"label":"Caps the code length","patterns":["\\d+\\s*lines","at most","under \\d+","short"]}],"hint":"Look at Maya and Priya's rows. Tell the AI how to tell they're the same person and which of their rows to keep.","rubricLabels":["Lowercases and trims the email column (str.strip() and str.lower()) before removing duplicates","Parses applied_on as a date (pd.to_datetime) and keeps each email's most recent row (sort by applied_on then drop_duplicates on email with keep=\"last\", or the equivalent)","Writes applicants_clean.csv with index=False and doesn't drop or rename any of the original columns"]}