Library › Coding AI › HR and recruiting
Dedupe applicants with pandas, keeping the latest one
Practice: Giving the right context. About 5 minutes.
About this exercise
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.
Common mistakes when you ask AI for this
- Not mentioning messy emails. The AI dedupes on the raw email, so Maya.Chen@ and maya.chen@ stay as two people. Try: Add: "Lowercase and trim emails before deduping."
- Not saying which row to keep. The AI keeps the first row it sees, which is often the oldest application. Try: Add: "Keep the most recent by applied_on."
- Leaving the output open. The AI writes the index as an extra column or trims columns it thinks you don't need. Try: Add: "Keep all columns, index=False."
- Getting a menu of options. The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself. Try: Add: "Give one script only, in one code block, no alternatives."
- Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."
What a strong prompt includes
- Normalizes emails
- Says which row to keep
- Sets the output
- Asks for one answer only
- Caps the code length
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)