Data Analysis · Analysis Workflow · lesson 12 of 12
Workshop: a full analysis
about 20 minutes · free · runs in your browser
Everything at once
This is the shape of a real job: read the file, clean it, join it, group it, and hand back a summary someone can act on.
The data is a month of orders. Some rows have a missing quantity. One order references a customer who is not in the customer list.
Your turn: write analyse(orders_csv, customers_csv) that:
- reads both CSV strings, treating
""andn/aas missing - drops orders with a missing
quantity - adds a
revenuecolumn (quantity * unit_price) - joins the customers on, keeping every remaining order
- returns a dictionary:
{
"orders": 4, # rows after cleaning
"revenue": 235.0, # total, rounded to 2dp
"by_region": {"north": 135.0, "south": 100.0},
"unknown_customer_orders": 1, # orders whose customer was not found
}
Regions come from the customer table; an order with no matching customer has no region and is counted separately rather than being dropped.
You start from this, and edit it in the browser:
import pandas as pd
from io import StringIO
def analyse(orders_csv, customers_csv):
# Read, clean, join, group, and return the summary.
pass