Skip to content

Lab · Data Science, Machine Learning and AI

Lab: a kirana shop's week of sales

Labbeginner· about 1.5 hours· 4 steps

The brief

Read a week of sales from a kirana shop's CSV export, then answer the owner's questions: how much each category earned, what sold best, and what a typical day looks like.

Why it matters

This is the first job of almost every data analyst: take an export from a billing or POS system, turn the text into numbers, and answer "how much, of what, per what?". Retail chains, quick-commerce apps and GST accountants run the same steps every week, usually with pandas, on bigger files.

Skills you practise

  • csv.DictReader with io.StringIO
  • converting text to numbers
  • defaultdict for grouping
  • Counter for counting
  • statistics.mean and median

What you will have at the end

report.py: a reusable weekly sales summary (revenue per category, top items, mean and median day) that works on any export with the same columns.

How it is marked (rubric, 100 points)
Correct numbersAll four checks pass, including the blank row and the empty-file cases.50
Clean data handlingText is converted to numbers once, at reading time, and the blank qty is skipped on purpose.20
Readable codeSmall functions with clear names; Counter and defaultdict used instead of long if-else chains.20
ExplainedYou can tell the owner in two sentences why the median day differs from the mean day.10

0/4 steps done

Step 1 of 4

Read the sales file

parse_sales(SALES_CSV) returns 14 row dicts with qty as an int and price as a float, skipping the row with a blank qty.

sales.py runs before your file, so SALES_CSV is ready to use. csv.DictReader with io.StringIO gives each row as a dict of strings. Every value from a CSV is text, so convert qty with int() and price with float() before any maths.

One row has a blank qty. int("") would crash, so check r["qty"].strip() and skip that row on purpose.

Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.