DEV Community

Học Nguyễn
Học Nguyễn

Posted on

Cleaning Messy CSVs & Batch-Generating AI Outreach Prompts With Zero-Dependency Python

When you work with scraped lead lists or exported spreadsheets, 80% of the time goes into two repetitive tasks:

  1. Deduplicating rows, trimming whitespace, and normalizing email casing.
  2. Turning those clean rows into personalized outreach or content prompts.

You don't need pandas or heavy SaaS subscriptions for either of these.

1. Clean & Deduplicate CSVs With Python's Built-In csv Module

import csv, re

def clean_cell(val: str) -> str:
    return re.sub(r"\s+", " ", (val or "").strip())
Enter fullscreen mode Exit fullscreen mode

Pairing csv.DictReader with a seen set lets you deduplicate thousands of rows by email and export directly to .csv, .json, or Markdown tables in milliseconds.

2. Batch-Fill Prompt Templates From Clean CSV Rows

Once your CSV is clean, a 30-line str.format(**row) loop merges each lead's name, company, trigger, and pain into structured B2B outreach or content repurposing prompts.


Ready-to-Run Toolkits (Zero Dependencies)

Hope this saves someone an hour of spreadsheet cleanup!

Top comments (0)