Library › Coding AI › Nonprofit staff

Add mail-merge greetings for couples and missing names

Practice: Showing an example of what you want. About 5 minutes.

About this exercise

Write a pandas script that reads donors.csv and writes mailing.csv with all the original columns plus a new salutation column. Rules: Dear Ana and Raj when there's a partner first name, Dear Ana when there's only a first name, and Dear Friend when the first name is blank. Names have stray spaces, so strip them. 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 stray spaces. The AI copies " Theo " as-is, giving Dear Theo with a double space. Try: Add: "Strip spaces from the names first."
  • Not showing all three greetings. The AI only handles one person per letter, or prints Dear nan. Try: Show them: "Dear Ana and Raj / Dear Ana / Dear Friend."
  • Leaving the output open. The AI keeps only a few columns or writes the index as an extra column. Try: Add: "All original columns plus salutation, 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

  • Shows all three greetings
  • Handles blanks and spaces
  • Sets the output
  • Asks for one answer only
  • Caps the code length

Practice this now ↑

Related exercises