Back to prompts
Code27.11.2026
Write a Python Script That Cleans Your Holiday Card Address List and Merges Duplicate Households
#python#csv#holiday cards#address list#deduplication#data cleaning#automation
You are a careful Python developer who writes small, readable scripts for everyday personal automation. Every December I send holiday cards, and my address list is a mess: it comes from an old spreadsheet, my phone contacts export, and a few addresses friends texted me. The same family often appears two or three times with slightly different spellings, and some rows are missing a postal code or apartment number. I want a script that cleans the list, groups likely duplicates into one household, and gives me a clean CSV I can use for printing labels or envelopes. Write the script and explain how to run it. Use only the Python standard library unless I say otherwise. Do not invent addresses, guess postal codes, or call any online address service. If something about my data is unclear, list it as [NEEDS INPUT] instead of assuming. My input files and their column names (paste the header row of each): [FILES] Country or countries the addresses are in, and the address format I need on the envelope: [COUNTRIES] How I want names shown for a household (for example The Garcia Family, or Ana and Ben Garcia): [NAME STYLE] My Python version and operating system: [ENVIRONMENT] Anything I already know is special (people who moved this year, people I do not send cards to anymore, international addresses): [NOTES] Requirements: 1. Read one or more CSV files and map their different column names to one standard set: names, street line 1, street line 2, city, region or state, postal code, country, and email or phone if present. Ask me for a mapping if a header is ambiguous. 2. Normalize text without changing meaning: trim spaces, fix capitalization of names and street words, unify common abbreviations such as St and Street only in a way I can switch off, and keep apartment and unit numbers intact. 3. Find likely duplicates using the street address and postal code first, then similar last names, using difflib from the standard library with a threshold I can change. Never merge two rows automatically when the street lines differ. 4. Group likely duplicates into one household, combine first names using [NAME STYLE], and write every merge decision to a review file so I can approve or undo it. 5. Flag rows that cannot be printed safely: missing street, missing city, missing postal code where my country needs one, or a postal code that does not match the basic pattern for that country. Do not fill these in. 6. Write three outputs: clean_addresses.csv ready for labels, review_merges.csv with every suggested merge and the original rows, and problems.csv with incomplete rows and the reason. 7. Add a dry run flag that prints a summary (rows read, households after merging, rows flagged) without writing files. 8. Keep personal data on my computer: no network calls, no logging of full addresses to the console beyond the summary. 9. Include a short sample input with clearly fake names and addresses so I can test the script safely before using my real list. 10. Explain how to open the clean CSV in a spreadsheet or a mail merge tool to print labels, without assuming a specific label brand. Deliverables: 1. Column mapping plan and questions 2. The complete Python script with comments 3. Sample fake input file 4. How to run it, including the dry run 5. How to review merges and fix flagged rows 6. Printing labels from the clean CSV
How to use this prompt
- 1Copy the prompt using the button above.
- 2Open your AI tool (ChatGPT, Claude, Midjourney, etc.)
- 3Paste and customize any variables in the prompt.
- 4Generate your result.
Tip
Fill every placeholder before you run the prompt. Keep one clear goal per run, then refine with a follow-up if needed.
When to use this prompt
- •Good for first drafts in Code
- •Keep variables filled so the model has enough context
- •Review AI output before sending or publishing