Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityGoogles neues Betriebssystem ist da – heißt jetzt aber komplett anders(22.09.2026 um 12:08 Uhr)
Windows Tipps & SecurityGooglebook-Premiere: Alle 5 Modelle ausprobiert – zwei stechen heraus(22.09.2026 um 12:30 Uhr)
Sichere ProgrammierungDeprecation notice: All-platform CodeQL bundle(22.09.2026 um 11:21 Uhr)
Sichere ProgrammierungCodeSOD: The John Cage Variable(22.09.2026 um 08:30 Uhr)
Windows Tipps & SecurityGoogles neues Betriebssystem ist da – heißt jetzt aber komplett anders(22.09.2026 um 12:08 Uhr)
Windows Tipps & SecurityGooglebook-Premiere: Alle 5 Modelle ausprobiert – zwei stechen heraus(22.09.2026 um 12:30 Uhr)
Sichere ProgrammierungDeprecation notice: All-platform CodeQL bundle(22.09.2026 um 11:21 Uhr)
Sichere ProgrammierungCodeSOD: The John Cage Variable(22.09.2026 um 08:30 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Cleaning messy CSVs without pandas: 3 tiny no-install scripts

Messy CSV exports are a tax on every data task: stray whitespace, duplicate rows, inconsistent headers, files too big to open. You don't always need pandas for this — Python's built-in csv module handles most of it with zero dependencies a…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Messy CSV exports are a tax on every data task: stray whitespace, duplicate rows, inconsistent headers, files too big to open. You don't always need pandas for this — Python's built-in csv module handles most of it with zero dependencies and code you can drop on any machine.



Here are three small patterns I reach for constantly.






1. Clean: dedupe, trim, fix headers






import csv

def clean(path, out):
seen = set()
with open(path, newline='', encoding='utf-8-sig') as f:
rows = list(csv.reader(f))
header = [h.strip().lower().replace(' ', '_') for h in rows[0]]
cleaned = []
for raw in rows[1:]:
cells = [c.strip() for c in raw]
if all(c == '' for c in cells):
continue # drop empty rows
key = tuple(cells)
if key in seen:
continue # drop duplicates
seen.add(key)
cleaned.append(cells)
with open(out, 'w', newline='', encoding='utf-8') as f:
w = csv.writer(f)
w.writerow(header)
w.writerows(cleaned)






Trims every cell, normalizes headers (First Name -> first_name), and removes empty/duplicate rows.






2. Split a huge CSV into chunks






import csv

def split(path, rows_per_file):
with open(path, newline='', encoding='utf-8-sig') as f:
reader = csv.reader(f)
header = next(reader)
chunk, part = [], 1
for row in reader:
chunk.append(row)
if len(chunk) >= rows_per_file:
_write(f'part{part}.csv', header, chunk); part += 1; chunk = []
if chunk:
_write(f'part{part}.csv', header, chunk)

def _write(name, header, rows):
with open(name, 'w', newline='', encoding='utf-8') as f:
w = csv.writer(f); w.writerow(header); w.writerows(rows)









3. Merge many CSVs into one






import csv, glob

def merge(pattern, out):
header = None
with open(out, 'w', newline='', encoding='utf-8') as o:
w = csv.writer(o)
for path in glob.glob(pattern):
with open(path, newline='', encoding='utf-8-sig') as f:
r = csv.reader(f)
h = next(r)
if header is None:
header = h; w.writerow(header)
w.writerows(r)









Why no pandas?



For one-off cleanups and small tools, the stdlib csv module is faster to ship: no install, runs anywhere Python 3.8+ runs, and the code stays readable enough to tweak for your own rules.






I cleaned these up into a tiny toolkit (proper CLI flags, edge cases, comments) so I stop rewriting them. If you'd rather grab them ready-made, it's $10 with full source: https://ko-fi.com/s/bfedf3fb78



What's your go-to for quick CSV wrangling?

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Cleaning messy CSVs without pandas: 3 tiny no-install scripts

Thematisch verwandte Begriffe: Cleaning, messy, CSVs, without · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94493 | A vulnerability was detected in Gigatech PDV5701 1.0.31_240305_112640. T…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick