Skip to content
Advertisement

Calculate z-score for multiple columns of dataset on groupby and transform to original shape in pandas without using loop

I have a data frame

JavaScript

Need to calculate Z-score for columns “c1”, “c2”, “c3” using groupby on “id”, and transform it to the original form without using the loop.

Expected output:

JavaScript

How to do it?

Advertisement

Answer

Use GroupBy.transform with DataFrame.join:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement