Library › Coding AI › Real estate agents
Shortlist listings for a buyer with pandas
Practice: Giving the right context. About 5 minutes.
About this exercise
Write a pandas script that reads listings.csv and writes shortlist.csv for your buyers, the Okafors: price at most 650,000, at least 3 beds, and zip 97211, 97217 or 97227 only. Add a price_per_sqft column rounded to whole dollars, sort by it from lowest to highest, keep only the top 5, and don't write the index. One code block, at most 12 lines, then under 25 words outside the code.
Common mistakes when you ask AI for this
- Not giving the buyer's limits. The AI can't know the Okafors' budget, beds or zips. Try: Add: "Price at most 650,000, 3+ beds, zips 97211, 97217, 97227."
- Leaving the ranking open. The AI sorts by price, or adds a column with long decimals. Try: Add: "Add price_per_sqft rounded to whole dollars, lowest first."
- Leaving the output open. The AI keeps every match and writes the index. Try: Add: "Top 5 only, shortlist.csv, 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
- Gives the budget and beds
- Gives the zips
- Sets the ranking
- 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)