Clean a CSV of transactions
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Tesla's technical phone screen, last asked May 2026. It tests data cleaning, csv and python.
Write a small batch pipeline that cleans a CSV file of transactions. It reads the raw file, validates and normalizes every row, sets aside rows that cannot be fixed, and writes a clean file plus a report of what was changed or rejected. Running it twice on the same input must give the same output.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
clean(input_path: str, output_path: str, rejects_path: str) -> dict— writes the clean rows and the rejected rows (each with a reason) and returns counts, such as{"read": 5, "written": 3, "rejected": 2, "fixed": {"currency": 1}}. - Columns:
transaction_id,account_id,timestamp,amount,currency.
Example
transaction_id,account_id,timestamp,amount,currency
T001,00042,2026-03-01 10:00:00,12.50,usd
T002,00042,03/01/2026 11:15,"1,200.00",USD
T003,,2026-03-01 12:00:00,5.00,USD
T001,00042,2026-03-01 10:00:00,12.50,usd
T004,00107,not a date,7.25,EUR
One reasonable result: T001 and T002 are written, with the timestamp in one ISO format, the amount as an exact decimal (1200.00), the currency upper-cased and account_id kept as the string "00042". T003 is rejected (missing account), the second T001 is dropped as a duplicate, and T004 is rejected (bad timestamp).
Constraints
- Identifiers are strings: never turn
00042into42. - Money uses exact decimals, not floats.
- The file may be larger than memory; process it as a stream.
Clarifying questions
- Which columns are required, and what is the expected type and format of each?
- Which timestamp formats and time zones can appear?
- What counts as a duplicate: the same
transaction_id, or the same full row? - Should a bad row be fixed, rejected, or should it stop the run?
- Who reads the rejects file, and what do they need in it?
What a strong answer covers
- The rules written down first, one per column, and applied by small, testable functions.
- Reading every field as text and converting on purpose, so ids keep leading zeros and amounts stay exact (
Decimal). - Deterministic output: stable row order, one canonical format per field, no dependence on wall-clock time.
- A rejects file with the original row and the reason, plus counts in a summary, so the run is auditable.
- Checks after cleaning: row counts add up, no duplicate ids, the amounts total the same as the accepted input.
- Streaming with the
csvmodule, and how deduplication memory grows with the number of ids.
Follow-ups
- The file is 50 GB. How do you deduplicate across it?
- New columns appear in next month's file. How does the pipeline react?
- Make the job safe to re-run after a crash half-way through.
- How would you run this daily and alert when the reject rate jumps?
Where it's asked
- Tesla · Technical phone screen · Last asked May 202645 min · 10 to 20 minutes on your background, then one compact coding, debugging or design task in CoderPad that must run
What it tests
data cleaning · csv · python
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
