Data ScienceInterview question banks

Feature engineering interview questions with pandas answers

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 27 September 2026 · 5 min read
In this article (9 sections)

Related programme: the Data Science course (6 months; ₹1,30,000 (inclusive of GST) · EMI from ₹5,000/month).

The short answer

Feature engineering interview questions test whether you can turn raw columns into inputs a model can use without leaking the answer into them. Expect questions on encoding categories, handling missing values, building features from dates and event histories, target encoding, and when scaling matters. What follows is an imagined 35-minute exchange with a junior data scientist candidate at a subscription business, with the pandas the candidate wrote and a short note after each exchange on what the interviewer was checking.

The setup

Interviewer: We predict whether a subscriber cancels in the next 30 days. You have a customers table and an events log. Let's build features together.

Exchange 1: categorical columns

Interviewer: The plan column has four values and city has about 900. How do you encode them?

Candidate: One-hot for plan, since there are only four values. For city, one-hot would create 900 sparse columns, so I'd group rare cities into "other" first, keep the most frequent ones, or use frequency or target encoding. For a tree model, frequency encoding is a cheap first try.

python
import pandas as pd

cust = pd.DataFrame({
    "cust_id": [1, 2, 3, 4, 5, 6],
    "plan": ["basic", "pro", "basic", "family", "pro", "basic"],
    "city": ["Noida", "Pune", "Noida", "Indore", "Noida", "Kochi"],
})
top = cust["city"].value_counts()
keep = top[top >= 2].index
cust["city_grouped"] = cust["city"].where(cust["city"].isin(keep), "other")
cust["city_freq"] = cust["city"].map(cust["city"].value_counts(normalize=True))
encoded = pd.get_dummies(cust, columns=["plan"], prefix="plan", dtype=int)
print(encoded)

Checking: that cardinality drives the choice, and that you know one-hot is not the only option.

Exchange 2: missing values

Interviewer: last_login_days is missing for 15% of customers. What do you do?

Candidate: First ask why. If it's missing because they never logged in, that's information, so I'd add a never_logged_in flag and fill the value with something like the maximum observed plus one. Filling with the mean would make never-active users look average. For a tree model I might leave NaN if the library supports it, but the flag still helps a linear model.

Checking: whether you treat missingness as a possible signal before imputing.

Exchange 3: features from an event log

Interviewer: Build activity features as of a cut-off date of 1 March.

Candidate: Only events before the cut-off, then counts over windows, recency and a trend.

python
import pandas as pd

events = pd.DataFrame({
    "cust_id": [1, 1, 1, 2, 2, 3, 3, 3, 3],
    "ts": pd.to_datetime(["2026-01-05", "2026-02-20", "2026-03-04",
                          "2026-01-10", "2026-01-12",
                          "2026-02-01", "2026-02-15", "2026-02-25", "2026-02-28"]),
})
cutoff = pd.Timestamp("2026-03-01")
past = events[events["ts"] < cutoff]          # nothing on or after the cut-off

def window_count(days):
    recent = past[past["ts"] >= cutoff - pd.Timedelta(days=days)]
    return recent.groupby("cust_id").size().rename(f"events_{days}d")

feats = pd.concat([window_count(30), window_count(60)], axis=1)
feats["days_since_last"] = (cutoff - past.groupby("cust_id")["ts"].max()).dt.days
feats = feats.fillna({"events_30d": 0, "events_60d": 0}).astype(int)
feats["trend_30_vs_60"] = feats["events_30d"] / (feats["events_60d"] - feats["events_30d"] + 1)
print(feats)

Customer 1's event on 4 March is excluded. Customer 2 has no events in the last 30 days, which is exactly the kind of signal a churn model wants.

Checking: the strict cut-off filter. Including the 4 March event is the most common leakage mistake in this question.

Exchange 4: target encoding

Interviewer: You mentioned target encoding for city. What's the risk?

Candidate: If I compute each city's churn rate on the full training set and use it as a feature for the same rows, each row's own label is inside its feature — the model learns something it can't have at prediction time, and small cities get extreme values. Two fixes: compute it out-of-fold, and smooth toward the overall rate.

python
import pandas as pd

train = pd.DataFrame({
    "city": ["Noida", "Noida", "Noida", "Pune", "Pune", "Kochi"],
    "churned": [1, 0, 0, 1, 1, 1],
})
prior = train["churned"].mean()
m = 2   # smoothing strength: behaves like m extra rows at the prior rate
stats = train.groupby("city")["churned"].agg(["sum", "count"])
stats["smoothed"] = (stats["sum"] + m * prior) / (stats["count"] + m)
print(stats.round(3))

Kochi's raw rate is 100% on one row; smoothed, it is 0.778, pulled toward the overall rate of about 0.667. In practice this is computed inside each cross-validation fold so no row sees its own label.

Checking: that you name leakage and small-sample noise without being prompted.

Exchange 5: dates

Interviewer: What features would you take from signup_date?

Candidate: Tenure in days at the cut-off, which usually matters most. Signup month or cohort if acquisition campaigns differ. Day-of-week is rarely useful for churn. I wouldn't feed the raw date as a number; the model would learn calendar position, which won't extrapolate to future customers.

Exchange 6: scaling

Interviewer: Do you standardise these features?

Candidate: For logistic regression with regularisation, yes, or the penalty hits large-scale features unevenly. For gradient-boosted trees, no — splits don't care about scale. Either way, fit the scaler on training data only and apply it to validation and test.

Exchange 7: which features to keep

Interviewer: You now have 150 features. How do you cut them down?

Candidate: Drop near-constant columns and exact duplicates first. Then check pairs with very high correlation and keep the more interpretable one. Use permutation importance on a validation set rather than the model's built-in importance, which favours high-cardinality features. And check any suspiciously strong feature for leakage — if one feature alone gets near-perfect accuracy, it's probably recording the outcome.

Checking: scepticism about features that look too good.

What made this candidate strong

Every answer tied the technique to the model type and to the moment of prediction. Two habits stood out: a cut-off date applied before any aggregation, and treating missing values and small groups as questions rather than cells to fill.

Practise by rebuilding Exchange 3 on any event log you have, with three different cut-off dates, and confirm the features change as expected. For the pandas mechanics behind these answers, see the pandas interview bank; the time-series bank goes deeper on leakage in time-ordered data. Feature pipelines built this way form part of the modelling projects in the Data Science programme.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.

Explore Data Science
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.