Menu

1 / 3

Clean a CSV without losing quoted text or rejected rows

DEV Community: python·Wenlo·1 day ago
#RH4IaHdZ
#devtopython#devto#dev#quantity#accepted
Reading 0:00
15s threshold

Wenlo

Posted on Nov 14

AI-assisted

A supplier export contains a comma inside one item name, quotation marks inside another, and two quantities that cannot enter a positive-supplies report. We need more than a split on commas: preserve the text, isolate rejected records, write a new CSV, and prove that reading it back preserves the accepted items.

Run the example

All illustrative records are fictional. Save the following as csv_roundtrip_audit.py. The complete script was run in PythonIDE on iPhone, and the screenshots show its actual source and output.

import csv from pathlib import Path from tempfile import TemporaryDirectory

# Fictional workshop supplies; never touches user files.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.