Nov-11-2020, 06:52 PM
Hi, I have a following problem. I need to compute means per category and time (in my df named as a "round"). My simplified df looks like bellow:
df = pd.DataFrame(data={ 'name':["a","a","a","b","b","c" ] , 'value':[5,4,3,4,2,1] , 'round':[1,2,3,1,2,1 ]})Desired output is:
new_df = pd.DataFrame(data={ 'name':["a","a","a","b","b","c" ] , 'value':[5,4,3,1,2,1] , 'round':[1,2,3,1,2,1 ] , 'mean_per_round':[5, 4.5 , 4, 1, 1.5, 1 ] })I am trying to use .shift() function, but it doesn`t help. Thanks for any suggestions!