human
applying functions to groups in pandas dataframe
assistant
Here is some code to apply function `log2` to the grouped values by 'type' in dataframe `df`

df.groupby('type').apply(lambda x: np.mean(np.log2(x['v'])))

#Warning: this code generation is experimental. Please inspect the code for any bugs before executing.