A GroupBy object provides a .transform() method that applies a function to the all values in the DataFrame in each group. We will examine the general transformation process and then look at two real-world examples.
Transforming groups of data
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)