O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The general process of transformation

The .transform() method of a GroupBy object applies a function to every value in the DataFrame and returns another DataFrame that has the following characteristics:

  • It is indexed identically to the concatenation of the indexes in all the groups
  • The number of rows is equal to the sum of the number of rows in all the groups
  • It consists of non-grouped columns to which pandas has successfully applied the given function (some columns can be dropped)

To demonstrate transformation in action, let's start with the following DataFrame:

New let's group by the Label column:

The following code performs a transformation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required