Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

← All challenges
IC01 · Delivery / logistics · ~10–15 min

A delivery just arrived

file intake · schema · inspection

CSV intake

The question

A delivery file has arrived. Establish what it contains before anyone uses it.

delivery.csv CSV intake

Your inputs

delivery.csv

One row is one delivery record. delivery.csv has a header row; dates are YYYY-MM-DD text.

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.
delivery.csv · first 5 of 16 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 16 rows
delivery.csv · 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
D013EastDelivered462.62026-04-07
D014WestDelivered383.32026-04-07
D015NorthPending7342026-04-08
D016EastReturned301.22026-04-08

The file is available in the Python working folder. Load it yourself.

Your task · A delivery just arrived

A delivery file has arrived. Establish what it contains before anyone uses it.

previewDataFramedimensionstupletypesSeries

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.

  1. First lookOutputpreviewDataFrame
    1. Load delivery.csv into df and keep its first five records in preview.
  2. Table shapeOutputdimensionstuple
    1. Store the shape of the full df in dimensions: its number of rows and columns (df.shape).
  3. Column typesOutputtypesSeries
    1. Store the data type of each imported column in types (df.dtypes).

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

How can you inspect a sample without shortening the imported table?

Hint 2 — Tools

read_csv(), head(), shape and dtypes

Revisit: Load a CSV · Take the first look · How big is it? · What types are these?

Hint 3 — Approach

Load the entire file, inspect a small preview, and collect metadata from the entire imported table.

Explained solution

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

df = pd.read_csv('delivery.csv')
preview = df.head()
dimensions = df.shape
types = df.dtypes
preview
View supplied setup

This code is already at the top of the editor.

import pandas as pd

Why these steps exist

  • The preview contains five rows; df.shape and df.dtypes describe the entire imported file.
  • Keeping df intact allows a later analyst to inspect records beyond the first five.

Another valid approach

You can inspect the complete file and keep a separate preview variable; slicing the imported df itself would lose records.

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.