Library › Coding AI › Finance and accounting
Find unmatched bank and ledger lines with pandas
Practice: Giving the right context. About 5 minutes.
About this exercise
Write a pandas script that compares bank.csv and ledger.csv and writes unmatched.csv with only the lines that appear in one file but not the other. Match on both date and amount, with amounts rounded to 2 decimals first because the ledger stores values like 310.4500001. Add a column named side whose values are exactly bank only or ledger only, and don't write the index. One code block, at most 14 lines, then under 25 words outside the code.
Common mistakes when you ask AI for this
- Not mentioning float noise. The AI compares raw amounts, so -310.45 and -310.4500001 look different. Try: Add: "Round amounts to 2 decimals before matching."
- Leaving the match key open. The AI matches on amount alone or tries the descriptions, which never agree. Try: Add: "Match on date and amount only."
- Leaving the output open. The AI prints both lists or keeps pandas' own left_only and right_only labels. Try: Add: "One file, a side column saying bank only or ledger only, 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
- Rounds the amounts
- Sets the match key
- Names the side labels
- Sets the output
- Asks for one answer only
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)