← Data analysis with Python

Asking good questions

Turn a vague wish into a question the data can answer.

Start this lesson

Analysis starts with a question, not with code. A good question is specific and can be answered with the columns you actually have. "Are our bikes popular?" is vague. "How many rides last longer than 20 minutes?" is specific: it names a column (minutes), a condition (more than 20) and a result (a count). Most questions break into the same small steps: pick the rows you care about, compute something, then compare.

rides = [
    {"member": "yes", "minutes": 12},
    {"member": "no", "minutes": 34},
    {"member": "yes", "minutes": 25},
]
# Question: what is the average ride length for members?
member_minutes = [r["minutes"] for r in rides if r["member"] == "yes"]
print(sum(member_minutes) / len(member_minutes))

The question named the rows (members), the column (minutes) and the calculation (average). The code follows those three parts in order.

If a question needs a column you do not have (for example "Why did riders choose bikes?" with no survey data), the honest answer is "this data cannot tell us". Saying so is part of good analysis.