Data analysis pandas

Use GroupBy.transform with std for repeating aggregate values, so is possible multiple by p column:

df['STD*p'] = df.groupby('G')['p'].transform('std').mul(df['p'])
print (df)
     G  month         p     STD*p
0   G1      1  0.040698  0.011816
1   G1      2  0.225641  0.065509
2   G1      3  0.236948  0.068792
3   G1      4  0.119340  0.034647
4   G1      5  0.779272  0.226243
5   G2      1  0.892169  0.439110
6   G2      2  0.062468  0.030746
7   G2      3  0.936044  0.460705
8   G3      1  0.509213  0.098856
9   G3      2  0.476719  0.092548
10  G3      3  0.407300  0.079071
11  G3      4  0.843261  0.163707
12  G4      1  0.882554       NaN

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top