logo

Creating Computed Columns

Computed columns derive their values from other columns. Pandas handles element-wise operations automatically.

Simple arithmetic:

df['total'] = df['price'] * df['quantity']

Each row's total equals its price times quantity.

Combine multiple columns:

df['full_name'] = df['first_name'] + ' ' + df['last_name']

Use conditions with np.where:

import numpy as np
df['status'] = np.where(df['score'] >= 60, 'pass', 'fail')

Computed columns are the heart of feature engineering - creating meaningful variables from raw data.

For advanced computed columns, see The Ultimate Pandas Bootcamp.