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

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

23.4 Timezone: naive vs IST चुका

By Ravindra Bagale

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

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

UTC आणि IST मिसळले की “हा order कालचा की आजचा?” चुकतं. Naive datetime = timezone माहिती नाही.

हे काय आहे?

Parse → tz_localize/tz_convert स्पष्ट करा. Course मध्ये IST (Asia/Kolkata) लक्ष्य.

कसं करायचं?

Step 1. Column dtype datetime का ते पाहा.

Step 2. जर UTC असेल तर Asia/Kolkata मध्ये convert.

Step 3. Date filter IST नुसार.

Step 4. Clock change / DST India मध्ये नाही — तरी timezone label ठेवा.

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

उदाहरण A — Localise fictional dispatch times.

import pandas as pd

ts = pd.DataFrame({
    "order_id": ["BLK-30", "BLK-31"],
    "city": ["Pune", "Kolhapur"],
    "dispatched_at": ["22-10-2026 21:05:00", "22-10-2026 21:20:00"],
    "delivered_at": ["22-10-2026 21:18:00", "22-10-2026 21:31:00"],
})
for c in ["dispatched_at", "delivered_at"]:
    ts[c] = pd.to_datetime(ts[c], dayfirst=True)
    ts[c] = ts[c].dt.tz_localize("Asia/Kolkata")
ts["mins"] = (ts["delivered_at"] - ts["dispatched_at"]).dt.total_seconds() / 60
print(ts[["order_id", "mins"]])

उदाहरण B — UTC feed mistaken as local.

utc_feed = pd.Series(["2026-10-22 15:35:00"])  # actually UTC
aware_utc = pd.to_datetime(utc_feed, utc=True)
ist = aware_utc.dt.tz_convert("Asia/Kolkata")
print("UTC", aware_utc.iloc[0])
print("IST", ist.iloc[0])  # evening in India

If Salman treats 15:35 UTC as 15:35 IST, the “evening rush” chart shifts by 5 hours 30 minutes.

उदाहरण C — Date-only filters stay simple.

days = pd.to_datetime(
    pd.Series(["15-10-2026", "20-10-2026", "25-10-2026"]), dayfirst=True
)
diwali_window = days.to_series().between("2026-10-15", "2026-10-22")
print(list(zip(days.dt.strftime("%d-%m-%Y"), diwali_window)))

For day-level EDA you often do not need tz — but say so in the README.