Two CSV exports, one schema, and a rejected-row log
Two order exports contained the same fields in different column orders. The first also had a blank customer name. The second had a row with an extra field. I used those four synthetic rows to test a small Python script that separates usable rows from rows a person needs to review. Input The east export puts the order ID first. Order,Name,Region 001,"Lee, Jordan",East 002, ,East The west export…
Two CSV exports were compared, despite sharing the same schema but with differing column orders. The first export featured a blank customer name, while the second contained a row with an extra field. A Python script was employed to separate valid rows from those requiring review. The script first resolved the headers of each file independently and mapped them to their respective columns.
The destination column order was derived from this mapping. The script then extracted and stripped values from each row according to the established positions. Upon running the script, two rows were deemed acceptable, while two others were flagged for review. The consolidated CSV file contained the accepted rows, with the rejected rows identified along with their source file, line number, and reason for rejection.
The script also prevented the overwriting of existing output directories and confirmed that it could handle UTF-8 CSV files with small local datasets.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.