File size: 579 Bytes
93ed35a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Feature engineering. Stateless transforms only. Anything that fits
on training data and applies to test data lives in `modeling/` — keeping
that boundary clean prevents train/test leakage."""

from __future__ import annotations

import pandas as pd


def add_calendar_features(df: pd.DataFrame, time_col: str) -> pd.DataFrame:
    """Hour, day-of-week, month — useful for most temporal models."""
    out = df.copy()
    ts = pd.to_datetime(out[time_col])
    out["hour"] = ts.dt.hour
    out["day_of_week"] = ts.dt.dayofweek
    out["month"] = ts.dt.month
    return out