Ravindra BagaleCourses & study guides

10. Dates, Times (IST), and Text

10.3 Text Extract

df["city_code"] = df["store_code"].str.split("-", n=1).str[0]
df["area"] = (
    df["store_code"]
      .str.split("-", n=1).str[1]
      .str.rsplit("-", n=1).str[0]
)
# Simple pincode pattern from a free-text address column (demo)
addr = pd.Series(["Flat 2, Kothrud 411038", "College Road 422005"])
pins = addr.str.extract(r"(\d{6})")
print(pins)

Steps in Jupyter

  1. Parse order_ts with dayfirst=True.
  2. Localise to Asia/Kolkata.
  3. Add hour and day_name().
  4. Split store_code into city_code and area.
  5. Filter evening orders: df[df["hour"] >= 18].

What you should see. Three IST-aware timestamps; city codes PUN, NSK, NGP.

Practice task

Create a column is_diwali_week True when date is between 15-10-2026 and 25-10-2026 inclusive. Count those rows.

Thodkyaat sangaycha tar (quick recap)

  • dayfirst / explicit format for Indian dates
  • Prefer IST (Asia/Kolkata) for class timestamps
  • str.split / str.extract for codes and pins

Samajla ka? Aata pudhe jaauya reshape — wide and long data.