DT1: Python and pandas for messy data

Lesson 1 of 5 · reading 15–25 minutes; practice and project time is on the module page

Raw data and the question behind it

🎯You'll be able to

Look at a raw file before cleaning it, say what one row means (its grain), and list the problems you can see.

🏠The everyday picture

Before a tailor cuts cloth, they measure twice and check the cloth for flaws. Cutting first and checking later wastes the cloth. Data is the same: look before you change anything.

📘What it really is

📝A worked example

Input: in the SabziSathi kit, open raw/orders/2026-10-05.csv in a text editor, then run:

import pandas as pd
df = pd.read_csv('raw/orders/2026-10-05.csv', dtype=str, keep_default_na=False)
print(len(df), df.duplicated().sum(), (df['customer_id'] == 'TEST').sum())
print(df['status'].value_counts())

Expected output: 317 10 2: 317 rows, 10 of them exact repeats of another row, and 2 staff test orders. The status counts show ten different spellings, such as Delivered, DELIVERED and delivered with spaces, for what are really three statuses. Measured on 1 November 2026 with pandas 3.1.0.

🌍Where it's used

📝Case scenario

A district office reported that a scheme reached 1.2 lakh families. An analyst noticed the list had one row per family member, not per family. The real number of families was about 31,000. The report was corrected before it went to the state government.

🖱️Try it

Open raw/customers.csv and raw/products.json. For each, write one sentence saying what one row (or one object) stands for, and list two things that look inconsistent. Success: you've found the mixed date formats in signup_date and the mixed upper- and lower-case emails.

⚠️Common mistakes

🛠️For your project

Project 1 starts here: the notes you write about the raw order files become the pipeline's cleaning rules and its tests.

✅Quick check

What is the grain of a table?

Show the answer

What one row stands for, such as one order line, one order or one customer.

Why keep raw files unchanged?

Show the answer

So you can clean them again when a rule turns out to be wrong.

← BackDT1
ProLearners Assist