Ravindra Bagale · Data Scienceसर्व coursesया course चे lessonsशोधाEnglish

Data Science · मराठी आवृत्ती

25.6 सामान्य चुका

By Ravindra Bagale

या course चे सर्व chapters (py + ch)

हे का शिकायचं?

Sort विसरणे, ascending चुकणे, groupby न करता global rank — तीन کلاसिक चुका.

हे काय आहे?

Checklist: sort, ascending, group keys, tie method, verify one group.

कसं करायचं?

Step 1. Sort झालं का.

Step 2. Leaderboard direction.

Step 3. Group key.

Step 4. एक group manually.

उदाहरणं: copy करा आणि चालवा

उदाहरण A — Broken cumsum (forgot sort).

import pandas as pd

messy = pd.DataFrame({
    "order_date": pd.to_datetime(["2026-10-24", "2026-10-22", "2026-10-23"]),
    "gmv": [140000, 88000, 125000],
})
print("wrong", messy["gmv"].cumsum().tolist())
fixed = messy.sort_values("order_date")
print("right", fixed["gmv"].cumsum().tolist())

उदाहरण B — Rank direction bug.

mins = pd.Series([18, 11, 25], name="delivery_mins")
# Wrong for "fastest": ranking high minutes first
print("wrong", mins.rank(ascending=False, method="dense").tolist())
print("right", mins.rank(ascending=True, method="dense").tolist())

उदाहरण C — Rolling on orders grain.

Zoya rolled amount_inr on 5,000 order rows with rolling(3) — that is “last 3 tickets”, not “last 3 days”. Aggregate by date first.