Beginner lesson, about 25 minutes
Your first data analysis in Python
Load a dataset, clean it, and answer a real question in about thirty lines of pandas.
This lesson walks through a complete, tiny analysis. You'll need Python with pandas installed, or a free online notebook. We'll use a small table of orders you can type in directly, so there's nothing to download.
1. Create the data
import pandas as pd
orders = pd.DataFrame({
"order_id": [1, 2, 3, 4, 5, 6],
"region": ["North", "South", "North", "East", "South", None],
"amount": [120.0, 80.5, 200.0, 55.0, None, 99.0],
})
print(orders)2. Look before you calculate
Real data is messy. Check for missing values before anything else, because they silently change averages and totals.
print(orders.isna().sum())
# region 1
# amount 13. Decide how to handle the gaps
There's no universal rule. Here, an order without an amount can't contribute to revenue, so we drop it. An order without a region still has revenue, so we label it rather than lose it.
clean = (
orders
.dropna(subset=["amount"])
.fillna({"region": "Unknown"})
)4. Answer the question
Which region brings in the most revenue, and how many orders is that based on?
summary = (
clean.groupby("region")
.agg(revenue=("amount", "sum"), orders=("order_id", "count"))
.sort_values("revenue", ascending=False)
)
print(summary)5. Say what it means, and what it doesn't
North leads on revenue, but from only two orders. With so little data, that tells you where to look next, not what to conclude. Saying that clearly is as much a part of data work as the code.
Next step: Applied Data Science starts here and takes you through statistics, modelling and communicating results.
Next lesson: SQL in one afternoon
Find the right program