Build a small data pipeline with pandas
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Cognition's build day round, last asked Sep 2024. It tests python, pandas and data pipelines.
A Python project round: implement a small data pipeline with pandas in about 90 minutes, then walk an engineer through your solution and answer questions on how you would extend it. The pipeline reads raw records, cleans them, transforms them into the requested output and writes it out, and the code should read like something a team could maintain.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
load(path: str) -> pd.DataFrame— reads the raw CSV with explicit column types and parsed timestamps. -
clean(df: pd.DataFrame) -> pd.DataFrame— drops exact duplicates and rows missing a required field, and normalizes values (trimmed strings, consistent case). -
transform(df: pd.DataFrame) -> pd.DataFrame— produces the requested aggregate, here one row per user per day with the total amount and the number of events. -
run(input_path: str, output_path: str) -> None— chains the steps and writes the result.
Example
user_id,ts,amount
u1,2026-01-01 09:00,10
u1,2026-01-01 18:00,
u2,2026-01-01 12:00,5
u1,2026-01-02 08:00,7
u2,2026-01-01 12:00,5
run(...) writes:
user_id,day,total_amount,events
u1,2026-01-01,10,1 # the row with no amount is dropped
u1,2026-01-02,7,1
u2,2026-01-01,5,1 # the repeated row counts once
Constraints
- Each step is a pure function from a DataFrame to a DataFrame, so it can be tested alone.
- Output order is deterministic (sorted by its keys).
Clarifying questions
- What do the inputs look like, how big are they, and are they CSV, JSON or several files to join?
- Which fields are required, and should bad rows be dropped, fixed or reported?
- Which time zone defines a "day"?
- Should the pipeline run once on a file, or incrementally as new data arrives?
What a strong answer covers
- Small, named steps with vectorized pandas (
drop_duplicates,dropna,groupby(...).agg(...),merge) rather than row loops. - Explicit dtypes and timestamp parsing at load time, so later steps don't guess.
- Bad data handled on purpose: counted or written to a rejects file, not silently lost.
- Unit tests per step on tiny DataFrames, plus one end-to-end test on a sample file.
- A clear explanation of the trade-offs when walking through the code.
Follow-ups
- The input no longer fits in memory: chunked reads, a columnar format such as Parquet, or a different engine.
- Run it daily and incrementally without double counting (idempotent outputs, partitions by day).
- Add a new output metric or source with minimal changes to the existing steps.
Where it's asked
- Cognition · Build day · Last asked Sep 2024480 min · Build your own end-to-end coding agent from scratch
What it tests
python · pandas · data pipelines · projects
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.
