out[ ]data - - - data key key one two one two one in [ ] _means df groupby('key 'mean(add_prefix('mean_'in [ ] _means out[ ]mean_data mean_data key - in [ ]pd merge(dfk _meansleft_on='key 'right_index=trueout[ ]data data key key mean_data mean_data - one two one - one - - two - this worksbut is somewhat inflexible you can think of the operation as transforming the two data columns using the np mean function let' look back at the people dataframe from earlier in the and use the transform method on groupbyin [ ]key ['one''two''one''two''one'in [ ]people groupby(keymean(out[ ] one - - - - - two - in [ ]people groupby(keytransform(np meanout[ ] joe - - - - - steve - wes - - - - - jim - travis - - - - - as you may guesstransform applies function to each groupthen places the results in the appropriate locations if each group produces scalar valueit will be propagated (broadcastedsuppose instead you wanted to subtract the mean value from each group to do thiscreate demeaning function and pass it to transformin [ ]def demean(arr)return arr arr mean(group-wise operations and transformations www it-ebooks info