Prompt
How do I remove invalid emails from a CSV list?
Latest observation
Oct 5, 2026
OpenAI APIWeb search: off
To remove invalid emails from a CSV list, you generally:
- Load the CSV
- Check each email against a validation rule
- Keep only the valid ones
- Save the cleaned CSV
Quick options
1) Using Excel / Google Sheets
If your CSV is small:
- Open it in Excel or Sheets
- Add a helper column with a formula to check email format
- Filter out invalid rows
- Export/save the cleaned file
Example basic check:
- In Excel, you can use formulas or data validation, but email validation is limited and not perfect.
2) Using Python
This is the most reliable for a CSV.
import pandas as pd
import re
# Load CSV
df = pd.read_csv("input.csv")
# Basic email regex
pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
# Keep rows where email is valid
df_clean = df[df["email"].astype(str).str.match(pattern, na=False)]
# Save cleaned CSV
df_clean.to_csv("cleaned.csv", index=False)
If your email column has a different name, replace "email" with that column name.
3) Using a command-line tool
If you’re comfortable with terminal tools, you can use Python one-liner scripts or CSV filters, but Python is usually easier and safer.
Important note
A regex can catch format errors, but it cannot guarantee an address actually exists or can receive mail. For that, you’d need:
- DNS/MX lookup
- SMTP verification
- An email verification service
Common cleanup steps
You may also want to:
- Trim spaces:
" test@example.com "→test@example.com - Convert to lowercase
- Remove duplicates
- Remove empty cells
Example in Python:
df["email"] = df["email"].astype(str).str.strip().str.lower()
If you want, I can give you:
- a Python script that removes invalid emails from your CSV,
- an Excel formula,
- or a version that also deduplicates and trims spaces.
Brands