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

21. Stats You Need for Data Work

21.2 Mean, Median and Mode with ₹ Orders

Why. Average is not one idea. Mean pulls toward extremes. Median sits in the middle. Mode is the most common value (useful for city or status, less often for ₹).

What.

Stat Plain English Good for
Mean Add all ₹, divide by count Stable, no huge outliers
Median Middle value after sorting Skewed ₹ baskets, salaries
Mode Most frequent value City name, payment method

How.

Compute all three in pandas

  1. Put amounts in a Series or DataFrame column amount.
  2. df["amount"].mean() — mean.
  3. df["amount"].median() — median.
  4. df["amount"].mode() — may return several values.
  5. For categories: df["city"].mode() or value_counts().idxmax().
  6. Always print count beside the stat.

Worked example A — Six Maharashtra cities (fictional delivered orders).

import pandas as pd

orders = pd.DataFrame({
    "order_id": [
        "BLK-261020-001", "BLK-261020-002", "BLK-261020-003",
        "BLK-261020-004", "AMN-261020-005", "BLK-261020-006",
        "BLK-261020-007", "AMN-261020-008", "BLK-261020-009",
        "BLK-261020-010", "BLK-261020-011", "AMN-261020-012",
    ],
    "city": [
        "Pune", "Pune", "Solapur", "Nashik", "Kolhapur", "Nagpur",
        "Pune", "Sambhaji Nagar", "Nashik", "Pune", "Solapur", "Nagpur",
    ],
    "customer": [
        "Ruhi Bagale", "Amir", "Zoya", "Salman", "Ravina", "Raja",
        "Shraddha Bagale", "Rani", "Shahrukh", "Ravindra Bagale", "Amir", "Zoya",
    ],
    "amount": [64, 189, 120, 95, 210, 150, 72, 340, 88, 1250, 110, 160],
    "status": ["Delivered"] * 12,
})

print("mean  ", round(orders["amount"].mean(), 1))
print("median", orders["amount"].median())
print("mode ₹", orders["amount"].mode().tolist())
print("mode city", orders["city"].mode().tolist())
print(orders.groupby("city")["amount"].agg(["count", "mean", "median"]).round(1))

What you should see. Overall mean is pulled up by Ravindra Bagale’s ₹1,250 festival hamper in Pune. Median stays near everyday kirana baskets. Mode for city is Pune (most rows). Mode for ₹ may be empty or weak — amounts rarely repeat exactly.

Worked example B — Same city, two stories.

pune = orders.loc[orders["city"] == "Pune", "amount"]
print("Pune mean", round(pune.mean(), 1), "median", pune.median())
print("Pune without max", round(pune[pune < pune.max()].mean(), 1))

When you drop the single ₹1,250 row, Pune’s mean falls hard; median barely moves. That is your teaching slide for “why median for ₹”.

Worked example C — Mode for ops, not for ₹.

print(orders["city"].value_counts())
# Payment-method style category (fictional)
pay = pd.Series(["UPI", "UPI", "Cash", "UPI", "Card", "UPI", "Cash"])
print("most common pay", pay.mode().iloc[0])

Raja in Nagpur asks “which pay method should the dark store promote?” Mode answers. Mean of UPI strings does not exist — right tool for the question.

Practice task

Build a 15-row fictional Amazon Now table for Nashik and Kolhapur with one extreme ₹2,999 order. Print mean and median for each city. Write one WhatsApp line that uses median, not mean.