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 ...