Ravindra BagaleCourses & study guides मराठी Track your progress

21. Stats You Need for Data Work

21.5 Correlation vs Causation

Why. A heat of “city vs delivery time” can trick you. Sambhaji Nagar shows longer minutes and more evening orders. Rain also hit that week. Correlation says “they move together”. Causation says “A makes B happen”. Ops decisions need the second — and this course stays honest: we rarely prove causation from one CSV.

What.

  • Correlation (here): when one numeric column is high, the other tends to be high (or low).
  • pandas: df["a"].corr(df["b"]) — simple linear association between −1 and 1.
  • Causation: needs design, domain knowledge, or careful experiments — out of scope as a claim from one classroom file.

How.

Talk carefully

  1. Pick two numeric columns (e.g. basket_size, delivery_mins).
  2. Scatter plot them; compute .corr().
  3. Write: “In this sample, larger baskets tend to come with longer minutes (corr ≈ 0.55).”
  4. Do not write: “Bigger baskets cause late delivery.”
  5. List other explanations: distance, rain, festival traffic, dark-store load.
  6. Suggest a next check (same city, same hour) — still not proof.

Worked example A — Basket size vs minutes (fictional Pune).

import pandas as pd

sample = pd.DataFrame({
    "order_id": [f"BLK-PUN-{i:03d}" for i in range(1, 11)],
    "items": [2, 3, 3, 4, 5, 5, 6, 8, 9, 12],
    "delivery_mins": [9, 10, 11, 12, 13, 14, 15, 18, 20, 28],
    "evening": [0, 0, 1, 0, 1, 1, 1, 1, 1, 1],
})
print("corr items vs mins", round(sample["items"].corr(sample["delivery_mins"]), 2))
print("corr evening vs mins", round(sample["evening"].corr(sample["delivery_mins"]), 2))

Both correlations can look “real”. Evening rush may drive minutes more than item count. Ravindra Bagale’s note to the team: “Association seen; cause not claimed.”

Worked example B — City averages are not personal blame.

city_avg = pd.DataFrame({
    "city": ["Pune", "Solapur", "Nashik", "Kolhapur"],
    "avg_mins": [14.2, 11.0, 13.5, 10.8],
    "rain_days": [4, 1, 3, 0],
})
print(city_avg["avg_mins"].corr(city_avg["rain_days"]))

A positive corr across four cities is a weak classroom toy — too few points. Never publish “rain causes delays” from four rows.

Worked example C — Safe wording bank.

Avoid Prefer
City causes late delivery This sample shows higher average minutes in …
Discount causes more orders Orders and discount flag rise together here
Proof that … Hint that …; needs a follow-up check

Ravindra Bagale's Tip

Interview madhe corr sangitla ki barobar causation nahi mhana. Ek honest sentence credibility vadhavto.