Transform and Filter Groups in Python

From the Pandas cheat sheet ยท Group and Aggregate ยท verified Aug 2026

Transform and Filter Groups

Return group-aligned values or remove whole groups.

python
df["team_avg"] = df.groupby("team")["score"].transform("mean")
๐Ÿ“Œ transform returns the original row shape
๐Ÿ” filter evaluates and keeps whole groups
โšก Built-in transforms are usually faster
๐ŸŽฏ Use agg when the output should be summarized
groupbytransformfilter

Continue with Pandas

Save the full cheat sheet or work through every related task.

More Python tasks

Back to the full Pandas cheat sheet