The analytics project lifecycle and the data audit
Most analytics work is a dashboard, not a model. This lesson follows a sales-dashboard project from the client's first ask to support after launch, compares it with the ML lifecycle, and gives you a reusable data-audit function.
Best read after Statistics & Machine Learning 7: Introduction to Machine Learning: Types, Business Framing and the ML Lifecycle in the Data Science & AI handbook.
1. Why it matters
- Clients rarely ask for "a model"; they ask to see sales against targets. Analysts deliver this first.
- Most delays come from data problems discovered late; the audit finds them in week one.
- The same discipline carries into ML projects, which add modelling, deployment and monitoring.
2. Key ideas
3. Step by step
- 1. Discovery: understand the business and agree KPIs, users, refresh and tool.
- 2. Data audit: profile every table; list findings and data requests.
- 3. Cleaning and preparation: duplicates, missing values, outliers, types, joins.
- 4. Load the data into Power BI (or Tableau / Excel).
- 5. Prepare views and measures (KPIs, trends).
- 6. Build the dashboard pages.
- 7. Validate and test against source totals with the client.
- 8. Publish to the server and set access rights.
- 9. Maintain and support: refresh failures, new requests, changes in the source.
4. Code you can run
Install once: pip install numpy pandas scipy scikit-learn statsmodels, then run python c3_data_audit.py. The data is generated inside the script, so it runs anywhere.
"""Analytics project lifecycle, step 2: the data audit, then step 5: the KPI views a dashboard needs.
A reusable audit function you can point at any table. Run: python c3_data_audit.py"""
import numpy as np
import pandas as pd
rng = np.random.default_rng(5)
n = 1200
sales = pd.DataFrame({
"order_id": np.arange(1, n + 1),
"order_date": pd.to_datetime("2026-04-01") + pd.to_timedelta(rng.integers(0, 183, n), unit="D"),
"rep": rng.choice(["Asha", "Ravi", "Meera", "John", "Sana"], n),
"region": rng.choice(["North", "South", "East", "West", None], n, p=[.27, .27, .2, .2, .06]),
"product": rng.choice(["Soap", "Shampoo", "Detergent", "Toothpaste"], n),
"qty": rng.integers(1, 40, n),
"unit_price": rng.choice([35.0, 120.0, 210.0, 55.0], n),
})
sales["amount"] = sales.qty * sales.unit_price
sales.loc[rng.choice(n, 8, replace=False), "amount"] = 250000.0 # data-entry outliers
sales = pd.concat([sales, sales.sample(15, random_state=1)]) # duplicate rows
def data_audit(df: pd.DataFrame) -> pd.DataFrame:
"""One row per column: type, missing share, distinct values and the range that shows outliers."""
out = []
for c in df.columns:
s = df[c]
row = {"column": c, "dtype": str(s.dtype), "missing_%": round(s.isna().mean() * 100, 1), "distinct": s.nunique()}
if pd.api.types.is_numeric_dtype(s):
row.update(min=s.min(), p1=s.quantile(.01), median=s.median(), p99=s.quantile(.99), max=s.max())
out.append(row)
return pd.DataFrame(out).set_index("column")
pd.set_option("display.width", 140)
print("STEP 2 Data audit")
print(f"rows={len(sales)} duplicate rows={sales.duplicated().sum()}")
print(data_audit(sales).round(1).to_string())
print("\nSTEP 3 Cleaning decisions taken from the audit")
clean = sales.drop_duplicates().copy()
clean["region"] = clean["region"].fillna("Unknown")
cap = clean["amount"].quantile(.99)
print(f"- removed {len(sales) - len(clean)} duplicates; filled {int(sales.region.isna().sum())} missing regions with 'Unknown'")
print(f"- capped amount at the 99th percentile ({cap:,.0f}); {(clean.amount > cap).sum()} rows changed")
clean["amount"] = clean["amount"].clip(upper=cap)
print("\nSTEP 5 KPI views for the dashboard")
target = pd.Series({"Asha": 550000, "Ravi": 500000, "Meera": 450000, "John": 480000, "Sana": 470000})
kpi = clean.groupby("rep").agg(revenue=("amount", "sum"), orders=("order_id", "count"))
kpi["target"] = target
kpi["achieved_%"] = (kpi.revenue / kpi.target * 100).round(1)
kpi["status"] = np.where(kpi["achieved_%"] >= 100, "On target", "Behind")
print(kpi.sort_values("achieved_%", ascending=False).to_string(float_format=lambda v: f"{v:,.0f}"))
monthly = clean.groupby(clean.order_date.dt.to_period("M")).amount.sum()
print("\nMonthly revenue trend:\n" + monthly.to_string(float_format=lambda v: f"{v:,.0f}"))
STEP 2 Data audit
rows=1215 duplicate rows=15
dtype missing_% distinct min p1 median p99 max
column
order_id int64 0.0 1200 1.0 13.1 600.0 1187.9 1200.0
order_date datetime64[us] 0.0 183 NaN NaN NaN NaN NaN
rep str 0.0 5 NaN NaN NaN NaN NaN
region str 6.1 4 NaN NaN NaN NaN NaN
product str 0.0 4 NaN NaN NaN NaN NaN
qty int64 0.0 39 1.0 1.0 20.0 39.0 39.0
unit_price float64 0.0 4 35.0 35.0 55.0 210.0 210.0
amount float64 0.0 142 35.0 55.0 1295.0 7980.0 250000.0
STEP 3 Cleaning decisions taken from the audit
- removed 15 duplicates; filled 74 missing regions with 'Unknown'
- capped amount at the 99th percentile (7,980); 9 rows changed
STEP 5 KPI views for the dashboard
revenue orders target achieved_% status
rep
Asha 591,935 272 550000 108 On target
Meera 475,560 228 450000 106 On target
Sana 484,155 251 470000 103 On target
Ravi 476,750 218 500000 95 Behind
John 436,990 231 480000 91 Behind
Monthly revenue trend:
order_date
2026-04 411,180
2026-05 387,970
2026-06 463,685
2026-07 424,195
2026-08 390,340
2026-09 388,020
Freq: M
5. Reading the output
- data_audit() works on any pandas table and returns one row per column; keep it in your toolkit.
- The audit reveals 15 duplicate rows, 6% missing regions and an amount maximum of 250,000 against a 99th percentile under 8,000: data-entry errors.
- Each cleaning decision is printed so it can go into the project log and be agreed with the client.
- The KPI view (revenue vs target by rep, achievement %, status) and the monthly trend are exactly the tables a Power BI page would read.
6. Common mistakes
| Mistake | Do this instead |
|---|---|
| Building visuals before agreeing KPIs | A beautiful dashboard of the wrong numbers gets rejected. Agree KPIs and definitions in writing first. |
| Skipping the audit | Problems surface during validation, weeks later. Audit on day one. |
| Silent cleaning | Every fix (dropped rows, capped values) must be logged and agreed. |
| No owner after launch | Agree support hours, refresh monitoring and a change process. |
7. Assignment
8. Interview questions
Walk me through an analytics project you delivered.
Use the nine steps: discovery and KPIs, audit, cleaning, load, views, dashboard, validation, publishing with access, and support, with one problem you found in the audit.
What is in a data audit?
Per column: type, missing share, distinct values, ranges and percentiles; plus duplicates, join checks and a list of cleaning actions and data requests.
How is an ML project lifecycle different?
It adds converting the business problem to a statistical one, feature preparation, training, evaluation, deployment, monitoring and retraining.