Feature Engineering for Analysts
Create new meaningful columns from existing data to improve analysis and modelling
Feature engineering is the process of creating new columns (features) from existing data to make analysis more meaningful. For data analysts, this means: extracting date parts, computing ratios, creating category bins, and deriving business metrics that are not in the raw data.
Good features often reveal insights that raw columns hide — for example, "day of week" from a timestamp, "days since last purchase" from a date, or "revenue per unit" from two separate columns.
Example
Key Points
- ✓Extract date parts (year, month, quarter, day of week) from timestamp columns
- ✓Compute ratio features: margin %, revenue per unit, return rate
- ✓pd.cut() creates categorical bins from continuous numeric data
- ✓shift(1) creates a lagged column — the previous row's value
- ✓Replace 0 with NaN before computing ratios to avoid division-by-zero errors
Practice Question
You want to flag whether an order was placed on a weekend. The DayOfWeek column has 0=Monday to 6=Sunday. Which code creates an IsWeekend binary flag?
Related Topics
Pandas DataFramesThe core Pandas data structure — a 2D table with rows and columnsString and Date Operations in PandasClean text columns and extract date parts with Pandas str and dt accessorsCapstone Project — Sales AnalysisEnd-to-end data analysis project: load, clean, analyse and visualise sales data