Back to search

groupby with agg vs transform vs apply

`agg` reduces groups, `transform` returns group-shaped output, and `apply` handles custom logic but is usually slower.

Pandas Medium Theory

groupby with agg vs transform vs apply

`agg` reduces groups, `transform` returns group-shaped output, and `apply` handles custom logic but is usually slower.

  • agg changes shape
  • transform keeps original row count
  • apply is flexible but costly

groupby with agg vs transform vs apply