Guided Notes

Transform: Dummy Variables & Text Cleaning

Cleaning categorical text with replace and regular expressions, then one-hot encoding with get_dummies.

What are dummy variables?

Slide 1 / 5

Machine learning models need numbers, but many columns hold categories: a project's sector might be Energy, Transportation, or Health.

Dummy variables (one-hot encoding) turn one categorical column into several 0/1 columns β€” one per category. A project in Energy gets 1 in the Energy column and 0 in all others.

pd.get_dummies(df['sector']) does it in one call.

ProjectEnergyTransportationHealth
P1100
P2010
P3001
← Transform: Missing & Duplicate Data