One-Hot Encoding

Encoding a categorical variable as a set of binary columns, one per category, for example membership_type becomes three 0/1 columns.

When to use

Use pd.get_dummies(...) before fitting models on categorical features. In regression use drop_first=True to drop one level per category and avoid the Dummy-Variable Trap (PS 02).

See DS Lec 3.

Appears in