Case File: The First Look
Sabi Logistics hands you a file of six months of deliveries. Before anyone draws a chart, find out what is in it: how many rows and columns, how much is missing, how many rows are repeats, and which city dominates. You do it in real pandas, on a file generated for you alone.
Sabi Logistics · Delivery 1
The First Look
A six-month export of every delivery has landed in your inbox and nobody has opened it
Chidi Founder · Phone call
Chidi. I have been promising the board numbers for weeks, and Ngozi finally exported every delivery we made since January into one file, deliveries.csv. I opened it in a spreadsheet and it froze. I do not need analysis yet. I need to know what we actually have: how many rows, how many columns, whether there are holes in it, whether anything is in there twice, and which city we deliver to most.
Amara says you can do this in Python in a few lines, and that the answer will be the same every time. That is exactly what I want.
The brief
What you need to know first.
- A DataFrame is a table: rows are records (here, deliveries), columns are fields.
pd.read_csv("deliveries.csv")reads a file into one. Always start by looking:df.head()shows the top rows,df.dtypesthe type of each column,df.describe()a summary of the numbers. - Size:
len(df)is the number of rows,df.shapeis(rows, columns). - Missing values appear as
NaN.df["driver"].isna()is True where a cell is blank, and.sum()counts the Trues. (Adding up True/False works because True is 1.) - Repeats:
df.duplicated()marks a row True if an identical row appeared earlier..sum()counts them. A repeated row usually means a double entry, and it would double-count money later. - Counting categories:
df["city"].value_counts()counts how often each city appears, biggest first, and.idxmax()returns the label of the biggest. - Pandas returns numpy numbers. The checker accepts them, but
int(...)is tidier when you want a plain number.
The lab: it gives you your own deliveries.csv (the numbers differ for every learner) and a script with five blanks. Press Run, then Check my answers. When all five are right it shows a report reference starting with GT{. Submit it at the bottom of the page.
Preparing your data…
Amara, reading over your shoulder: “You said 14 rows had no driver. Chidi will ask whether we should just delete them. What would you tell him, and what would you want to know first?”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Chidi: “So the file is real, a bit dirty, and Lagos is our biggest market. Good. Now I trust the next question.”
What a senior analyst would do next. Keep a short data-quality note at the top of every analysis: row and column counts, missing values per column (df.isna().sum() gives all columns at once), duplicates, and the odd things you saw. Decide what to do about each problem before you calculate anything, and write it down, because a missing-driver row that you silently drop changes every later number. Missing is not the same as zero: a blank revenue means “unknown”, a revenue of 0 means “earned nothing”, and the two need different handling.
The habit: look first (head, shape, dtypes, isna, duplicated), then ask your question. An hour spent looking saves a day of wrong answers.
Write the data-quality note
Write the short data-quality note you would put at the top of this analysis: how many rows and columns, what is missing and how many, what is repeated and how you found it, which city is biggest, and what you would do about the missing drivers and the repeated rows before calculating anything else.
🧪 Want to practise this on your own computer? See how to set up your lab →