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
- Parse
order_tswithdayfirst=True. - Localise to
Asia/Kolkata. - Add
hourandday_name(). - Split
store_codeinto city_code and area. - 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.extractfor codes and pins
Samajla ka? Aata pudhe jaauya reshape — wide and long data.