Data Science · मराठी आवृत्ती
10.3 Text मधून code आणि pincode काढूया
Store code मधून city_code आणि area वेगळे करूया. Address मधून सहा digits शोधण्यासाठी छोटा regex demo आहे:
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)
Jupyter मध्ये steps
- order_ts dayfirst=True वापरून parse करा.
- या sample ला Asia/Kolkata localise करा.
- hour आणि day_name() जोडा.
- store_code मधून city_code आणि area वेगळे करा.
- Evening orders filter करा:
df[df["hour"] >= 18].
तीन IST-aware timestamps आणि PUN, NSK, NGP हे city codes दिसतील.
Practice
is_diwali_week column तयार करा. या काल्पनिक exercise मध्ये 15-10-2026 ते 25-10-2026 दोन्ही दिवस धरून date असेल तर True द्या आणि rows मोजा. हा practice window आहे, अधिकृत festival calendar नाही.
Recap
- Indian dates साठी dayfirst किंवा explicit format.
- Class च्या local timestamps साठी IST — Asia/Kolkata.
- Codes आणि pins साठी str.split / str.extract.
पुढे wide आणि long data पाहू.