← All Python interview questions

One-hot encode a categorical column for modelling

MediumPandas — CleaningFractalMu Sigma

Before modelling, the plan column has to become numeric dummy columns.

Write encode(df) that returns the DataFrame with plan replaced by one-hot columns named plan_<value>, dropping the first category to avoid collinearity, with the remaining columns as integers (0/1) and the original columns kept.

Practising alone only goes so far — our live cohorts pair Python and Pandas depth with dashboards, agentic analytics projects and mock interviews.

Explore the program