{"id":"code-work-np-pandas-mailing-salutations","audience":"nonprofit","category":"coding","track":"coding","technique":"examples","title":"Add mail-merge greetings for couples and missing names","free":false,"task":"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.","materialLabel":"Donor export, first rows (attached to your prompt automatically)","material":"donors.csv - year-end appeal list (exported from the donor database)\n\nfirst_name,partner_first_name,last_name,address,city,zip\nAna,Raj,Mehta,14 Birch Ln,Riverbend,97230\n Theo ,,Brandt,9 Alder Ct,Riverbend,97231\n,,Okafor Family Trust,200 Main St,Riverbend,97230\nMarisol, Luis ,Vega,77 Cedar Rd,Fairview,97024\nAiko,,Tanaka,5 Pine St,Riverbend,97231\n\nNotes from Grace (development):\n- The print shop merges the letter greeting from a column called salutation.\n- Trusts and foundations have no first name in the database.\n- Last year a typo sent \"Dear  Theo\" with two spaces and a donor noticed.\n- Couples who give together want both names on the letter.\n- About 1,400 households get the appeal.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":14},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Not mentioning stray spaces","why":"The AI copies \" Theo \" as-is, giving Dear  Theo with a double space.","fix":"Add: \"Strip spaces from the names first.\"","checks":["r0"]},{"title":"Not showing all three greetings","why":"The AI only handles one person per letter, or prints Dear nan.","fix":"Show them: \"Dear Ana and Raj / Dear Ana / Dear Friend.\"","checks":["r1"]},{"title":"Leaving the output open","why":"The AI keeps only a few columns or writes the index as an extra column.","fix":"Add: \"All original columns plus salutation, 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":"Shows all three greetings","patterns":["dear friend","and raj","dear ana"]},{"label":"Handles blanks and spaces","patterns":["strip","spaces","blank","missing"]},{"label":"Sets the output","patterns":["mailing\\.csv","index=false","all (the )?(original )?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":"Show the AI the three kinds of greeting with real names from the list, and mention the messy spaces.","rubricLabels":["Strips spaces from first_name and partner_first_name and treats missing values as blank (for example fillna(\"\") then str.strip())","Builds salutation as Dear <first> and <partner> when there's a partner, Dear <first> with only a first name, and Dear Friend when the first name is blank","Writes mailing.csv with every original column plus salutation, using index=False"]}