← Back to Data Science track
Reference

Data Science Cheat Sheet

A reference for the ideas this track is building — frame a question, get the data, clean it, explore it, model carefully, and communicate a decision. It is not a full library of every data-science package. Three lessons are live; the rest of the map is still ahead.

What the work is
A working definition
Turn a decision into a question,
then into evidence someone can act on.
The lifecycle in the live workflow lesson:
  frame, collect, clean and explore,
  analyse or model, validate, communicate.
Four titles
data analyst      what already happened
data scientist     clean, check, sometimes predict
ML engineer        ship and run the model
data engineer      the pipes that make rows exist
The live lesson is the long version of this split.
Where the track is
Live now
  what data science is
  the workflow
  how the role differs from the other three
Ahead
  a browser Python playground and StreamPulse
  cleaning, exploration, charts, then a first model
This page stays at that scope.
Frame the question
A question has parts
the decision it will change
the unit: a user, a day, a title
the metric
the time window
"Analyze the data" is not a plan.
One you could answer
"Which plan has the higher cancel rate
 this quarter, in this extract?"
Names the metric, the group, and the window.
It does not pretend to know why.
Write this first
What result would change the decision?
What will you refuse to claim?
Which table could even hold the answer?
If no table can, the question is still a wish.
Data you can name
StreamPulse tables
users            who signed up
titles           the catalog
subscriptions    plan, price, status, cancel reason
watch_history    minutes and whether they finished
ratings          a score and a review
One fictional service, reused as the track grows.
Grain
A row is one observation.
A column is one attribute.
user_id and title_id are how tables meet.
If you cannot name the grain, do not average yet.
A row in plain Python
user = {
    "user_id": 1,
    "country": "IN",
    "plan": "basic",
    "signup_date": "2024-01-03",
}
# later lessons move this into a table tool
# sketch — that library is not required here
Clean
Missing
def missing(value):
    return value is None or value == ""

def complete(rows, keys):
    kept = [
        row for row in rows
        if all(not missing(row.get(key)) for key in keys)
    ]
    return kept, len(rows) - len(kept)
Types
def as_number(value):
    try:
        return float(value)
    except (TypeError, ValueError):
        return None
# a blank that became 0 will move every mean
Before you group
Duplicates: same key twice. Keep one, and say which.
Outliers: far from the rest. A bug, or the story.
Strings: strip space and agree on case.
Write down every drop. A silent filter is a new dataset.
Explore
Mean and median
def mean(xs):
    return sum(xs) / len(xs)

def median(xs):
    ordered = sorted(xs)
    mid = len(ordered) // 2
    if len(ordered) % 2:
        return ordered[mid]
    return (ordered[mid - 1] + ordered[mid]) / 2
# skew pulls the mean and leaves the median
Count by a key
def counts(rows, key):
    tally = {}
    for row in rows:
        value = row.get(key)
        tally[value] = tally.get(value, 0) + 1
    return tally
Together is not because
Two columns can move together because
  one influences the other,
  both share a cause,
  or the collection process ties them.
Correlation is a clue. It is not the decision.
A first pass
how many rows, and how many missing
the grain
one distribution: the shape, not only the average
one comparison across a group
Stop when the next chart would not change the question.
Model, lightly
Beat a boring rule
def majority(labels):
    return max(set(labels), key=labels.count)

# a model maps features to a guess
# a baseline — majority class, or the mean — comes first
# if you cannot beat it, do not add complexity
Hold some rows out
def holdout(rows, frac=0.8):
    cut = int(len(rows) * frac)
    return rows[:cut], rows[cut:]
# shuffle, or cut by time if the decision is about later
# test rows do not teach the rule
Names the later lessons use
linear regression    a weighted sum for a number
logistic regression  a weighted sum, then a probability
train / test split   so the score is on unseen rows
overfitting          memorising this extract
# sketch — no modelling library is imported here
Communicate
Three lines
the question
the number, with how many rows
the caveat
A chart is optional. The sentence is not.
Say the size
# shape of a result, not a finding from the dataset
# "4 of 10 basic rows in this extract are canceled.
#  The extract is small, so this is a hint."
"Basic looks worse" is not a result.
If you do draw it
bar       compare categories
line      something over time
scatter   two numbers, one point each
The title states the claim, not the chart type.
Chart libraries show up in later lessons, not this page.
How the roles differ
Read the verbs
pipelines, warehouses, freshness   data engineering
dashboards, SQL, weekly KPIs       analytics
questions, checks, a careful model data science
deploy, latency, monitoring        ML engineering
The job title on the post is the weak signal.
One question, four owners
"Why did cancels rise?"
  analyst        slice what already happened
  scientist      test a reason, and attach a caveat
  ML engineer    score who might cancel next, in production
  data engineer  make sure yesterday's events arrived
A day, not a toolbox
The live "what is data science" lesson
walks a working day, not a package list.
Excel still fits a small tidy table.
Python is how a cleaning step gets repeated
and shown. The playground lesson is still ahead.
Validate the claim
Before you send it
Is "cancel" the same column in every table?
Did a join multiply rows?
Is the window the one the decision uses?
Would someone act — and on which number?
A rate you can recompute
def rate(flags):
    if not flags:
        return None
    return sum(1 for flag in flags if flag) / len(flags)
# print the numerator and the denominator beside it
Leakage
A feature that only exists after the outcome
makes a brilliant score that fails next month.
When the decision is about the future,
hold out a later period, not a random shuffle
of the same week.

Projects to build

The fastest way to make this stick. Build one, then put it in your portfolio.

Beginner

Question card

For a streaming service like StreamPulse, write one decision, one metric, the tables you would need by name, and what result would change your mind. Do not compute anything yet.

problem framingmetricsgrain
Beginner

Clean ten rows

Type about ten subscription dicts in pure Python. Count missing cancel reasons, drop rows with no plan, and write two lines on what you removed and why.

missing valuestypesa cleaning log
Intermediate

Mean, median, and a group

On a small list of watch minutes you type yourself, report mean and median and a count by plan or device. Say whether the mean is a fair summary of that list.

distributionsgroupby by handskew
Intermediate

Stakeholder note

Half a page: the question, what you cleaned, one comparison, and one caveat. No charting library. A reader who skips the code should still know what not to do.

storytellingsample sizecaveats
Advanced

Model card without a library

Write the guess you want (cancel or not), the baseline (majority class), what you would hold out, which mistake is worse, and what you will not claim from a few dozen rows. Optional: compute the baseline with the majority helper on this page.

baselinesholdoutoverclaiming