Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

← All challenges
WC08 · Delivery / logistics · ~10–20 min

Combine two batches

schema alignment · combine tables · ordering

Combined handoff

The question

Combine two compatible delivery exports into one handoff.

df + second Combined handoff

Your inputs

df

Both duration and minutes are elapsed minutes. Preserve both source tables.

Field meanings and units
delivery_id
Delivery identifier.
depot
Depot responsible for the delivery.
status
Recorded delivery state.
minutes
Elapsed duration in minutes; unknown is not zero.
weight_kg
Weight in kilograms.
date
Calendar date supplied as YYYY-MM-DD text unless the task states it is invalid.
df · first 5 of 12 rows
delivery_iddepotstatusminutesweight_kgdate
D001EastDelivered321.22026-04-01
D002WestDelivered481.92026-04-01
D003NorthPending252.62026-04-02
D004EastReturned613.32026-04-02
D005WestDelivered4542026-04-03
View all 12 rows
df · complete input
delivery_iddepotstatusminutesweight_kgdate
D001EastDelivered321.22026-04-01
D002WestDelivered481.92026-04-01
D003NorthPending252.62026-04-02
D004EastReturned613.32026-04-02
D005WestDelivered4542026-04-03
D006NorthDelivered371.22026-04-03
D007EastPending721.92026-04-04
D008WestReturned292.62026-04-04
D009NorthDelivered333.32026-04-05
D010EastDelivered4942026-04-05
D011WestPending261.22026-04-06
D012NorthReturned621.92026-04-06

second

Second batch uses duration for minutes, recorded as numeric text. IDs do not overlap between batches.

Field meanings and units
delivery_id
Delivery identifier.
depot
Depot responsible for the delivery.
status
Recorded delivery state.
weight_kg
Weight in kilograms.
date
Calendar date supplied as YYYY-MM-DD text unless the task states it is invalid.
duration
Elapsed minutes, supplied as text.
second · first 5 of 12 rows
delivery_iddepotstatusweight_kgdateduration
D112NorthReturned1.92026-04-0662
D111WestPending1.22026-04-0626
D110EastDelivered42026-04-0549
D109NorthDelivered3.32026-04-0533
D108WestReturned2.62026-04-0429
View all 12 rows
second · complete input
delivery_iddepotstatusweight_kgdateduration
D112NorthReturned1.92026-04-0662
D111WestPending1.22026-04-0626
D110EastDelivered42026-04-0549
D109NorthDelivered3.32026-04-0533
D108WestReturned2.62026-04-0429
D107EastPending1.92026-04-0472
D106NorthDelivered1.22026-04-0337
D105WestDelivered42026-04-0345
D104EastReturned3.32026-04-0261
D103NorthPending2.62026-04-0225
D102WestDelivered1.92026-04-0148
D101EastDelivered1.22026-04-0132

The editable setup in Your Python creates these inputs when you run it.

Your task · Combine two batches

Combine two compatible delivery exports into one handoff.

combinedDataFramerecord_countnumber

Deliverables

Make the outputs listed below. Use each name exactly as shown. Then choose Check answer.

Python name key

Teal outlines name table columns. Violet left rules name Python objects. Dotted rules mark syntax, functions and parameters. Use each name exactly as shown.

Words in this task
numeric
a number, rather than text
  1. Combined deliveriesOutputcombinedDataFrame
    1. Use df and second as your inputs.
    2. In a separate copy of second, rename duration to minutes and convert its numeric text to numbers.
    3. Append the two batches and keep every row, using the same columns in the same order as df.
    4. Store the finished table in combined.
    5. Keep both inputs unchanged.
  2. Combined record countOutputrecord_countnumber
    1. Count all rows in combined and store that number in record_count.

Data policy Keep all supplied source tables unchanged. Work on separate outputs.

Help Hints & explained solution

Choose the amount of help you need. Opening one hint does not reveal the others.

Hint 1 — Think

Are similarly named fields expressing the same quantity in the same unit?

Hint 2 — Tools

rename(), to_numeric() and concat()

Revisit: Rename columns · Convert numeric text · Stack datasets · Sort and reset

Hint 3 — Approach

Align the second batch’s name and numeric type, append all rows using df column order, then count the combined records.

Explained solution

Add these lines below # Your work in the editor. The supplied input setup is already there.

batch = second.rename(columns={'duration': 'minutes'}).copy()
batch['minutes'] = pd.to_numeric(batch.minutes)
combined = pd.concat([df, batch[df.columns]], ignore_index=True)
record_count = len(combined)
combined
View supplied setup

This code is already at the top of the editor.

import pandas as pd

# Supplied input: df (12 rows)
df = pd.DataFrame(
    [
        ('D001', 'East', 'Delivered', 32, 1.2, '2026-04-01'),
        ('D002', 'West', 'Delivered', 48, 1.9, '2026-04-01'),
        ('D003', 'North', 'Pending', 25, 2.6, '2026-04-02'),
        ('D004', 'East', 'Returned', 61, 3.3, '2026-04-02'),
        ('D005', 'West', 'Delivered', 45, 4, '2026-04-03'),
        ('D006', 'North', 'Delivered', 37, 1.2, '2026-04-03'),
        ('D007', 'East', 'Pending', 72, 1.9, '2026-04-04'),
        ('D008', 'West', 'Returned', 29, 2.6, '2026-04-04'),
        ('D009', 'North', 'Delivered', 33, 3.3, '2026-04-05'),
        ('D010', 'East', 'Delivered', 49, 4, '2026-04-05'),
        ('D011', 'West', 'Pending', 26, 1.2, '2026-04-06'),
        ('D012', 'North', 'Returned', 62, 1.9, '2026-04-06'),
    ],
    columns=['delivery_id', 'depot', 'status', 'minutes', 'weight_kg', 'date'],
)

# Supplied input: second (12 rows)
second = pd.DataFrame(
    [
        ('D112', 'North', 'Returned', 1.9, '2026-04-06', '62'),
        ('D111', 'West', 'Pending', 1.2, '2026-04-06', '26'),
        ('D110', 'East', 'Delivered', 4, '2026-04-05', '49'),
        ('D109', 'North', 'Delivered', 3.3, '2026-04-05', '33'),
        ('D108', 'West', 'Returned', 2.6, '2026-04-04', '29'),
        ('D107', 'East', 'Pending', 1.9, '2026-04-04', '72'),
        ('D106', 'North', 'Delivered', 1.2, '2026-04-03', '37'),
        ('D105', 'West', 'Delivered', 4, '2026-04-03', '45'),
        ('D104', 'East', 'Returned', 3.3, '2026-04-02', '61'),
        ('D103', 'North', 'Pending', 2.6, '2026-04-02', '25'),
        ('D102', 'West', 'Delivered', 1.9, '2026-04-01', '48'),
        ('D101', 'East', 'Delivered', 1.2, '2026-04-01', '32'),
    ],
    columns=['delivery_id', 'depot', 'status', 'weight_kg', 'date', 'duration'],
)

Why these steps exist

  • The second batch uses a different name and numeric text for the same duration unit. Both must be aligned.
  • Appending retains every record; matching the batches by depot instead would combine unrelated deliveries.

Another valid approach

Align names and types in separate copies before concatenation; the order of those independent preparations may differ.

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Named outputs appear below when you run.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.