question 448 Data Formats & Analytical Workflows · medium
Check a CSV export before sending it
Before a summary file is sent to finance, a script checks it. Write export_problems(path, columns): read the CSV as text and return a list of problems in this order: "index column" if the first column is unnamed (pandas reads it as Unnamed: 0); "missing: <name>" for each expected column that isn't there, in the order given; "extra: <name>" for each column that isn't expected (ignoring the index column), in file order; "too many decimals: <name>" for each expected column containing a value with more than 2 digits after the decimal point.
Function
export_problems(path, columns)columnsthe expected column names, e.g.
["payment_type_id", "trips", "revenue"]Returnsa list of problem texts;
[] for a clean file