Saltar al contenido
← volver

Merge CSV files with different column orders using only Python's standard library

DEV · dev.to Publicado:

Merging monthly CSV exports sounds trivial until the files have different column orders, extra columns, or a BOM from Excel. Here is a short standard-library script that handles all three and records where each row came from. import csv, sys, glob def merge(paths, out): rows, cols = [], [] for p in paths: with open(p, newline="", encoding="utf-8-sig") as f: r = csv.DictReader(f) for c in r.fieldnames or []: if c not in cols: cols.append(c) for row in r: row["source_file"] = p rows.append(row) c…

Leer original →

Más de DEV