# 10.3 Text मधून code आणि pincode काढूया

Source: https://ravindrabagale.com/mr/datascience/ch10-dates-times-ist-and-text/10-3-text-extract.html
Language: mr (Marathi with English technical terms)

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 पाहू.

रवींद्र बागले यांची tip

सहा digits सापडले म्हणजे तो खरा valid pincode आहे असं सिद्ध होत नाही. Extract करणं आणि validate करणं हे वेगळे steps आहेत.
