0Pricing
Data Science Academy · Lesson

transform for Group-Wise Features

Aligning group stats back to rows.

agg Shrinks, transform Keeps

Where agg returns one row per group, transform returns a value for every original row, same length as the input.

Why That Matters

Because transform keeps the original shape, you can drop its result straight back into your DataFrame as a new column.

df["city_avg"] = df.groupby("city")["sales"].transform("mean")

All lessons in this course

  1. Split-Apply-Combine Explained
  2. Multiple Aggregations With agg
  3. Group by Several Keys
  4. transform for Group-Wise Features
← Back to Data Science Academy