Applying functions to groups

After splitting our data into the desired groups, the next step is to independently apply a function to each group of data. This step allows us to implement various techniques in each group to get different outputs based on our data requirements.

Beyond performing the common mean and sum aggregations on grouped data, we can apply various other functions to the groups. These functions can be classified into three categories:

  • Aggregate: Calculate a summary statistic for each group, e.g., compute mean and standard deviation values.

  • Transform: Perform group-wise computations and return an output object that retains the same shape, e.g., scale the values in each group based on each group’s min-max values.

  • Filter: Remove groups based on a group-wise computation that gives a boolean (True/ False) output, e.g., discard groups with a mean value below a certain threshold we define.

We’ll continue working with the credit card dataset for the following examples.

Get hands-on with 1200+ tech skills courses.