Arithmetic between columns
What it is
Column-wise operations produce new columns: df["margin"] = df["revenue"] - df["cost"]. They align on the index and skip missing values per element.
Why it matters
This is the fast path — compiled, element-wise, no Python per row.
In the real world: Calculating profit per order as revenue minus cost minus shipping, the number every retail business watches.
df["margin"] = df["revenue"] - df["cost"]
df["margin_pct"] = df["margin"] / df["revenue"].replace(0, np.nan)Dividing by a column that contains zeros gives inf rather than an error. Guard it explicitly or the infinity propagates into every later aggregate.