Topics in this subject
Pandas 1 min read Updated 4 Aug 2026

Project 6 — Feature Engineering & ML Preprocessing

df = pd.DataFrame({

df = pd.DataFrame({
    'age':[25,32,47,51], 'income':[40,60,80,120],
    'gender':['M','F','F','M'], 'city':['NYC','LA','SF','NYC']})

# 1. Numeric scaling (standardization) with NumPy
num = ['age','income']
df[num] = (df[num] - df[num].mean()) / df[num].std()

# 2. One-hot encode categoricals
df = pd.get_dummies(df, columns=['gender','city'], drop_first=True)

# 3. Interaction feature
df['age_income'] = df['age'] * df['income']

# 4. Binning
# df['age_bin'] = pd.qcut(df['age'], q=3, labels=['low','mid','high'])

Pipeline: scale numerics → encode categoricals (get_dummies, drop_first avoids collinearity) → derive interactions → bin. This is the standard tabular-ML prep flow.