Say I have the following DataFrame:
data = pd.DataFrame({'id' : ['1','2','3','4','5'], 'group' : ['1','1','2','1','2'],
'state' : ['True','False','False','True','True'], 'value' : [11,12,5,8,3]})
I would like to add to the previous dataframe, a new column with the average 'state', which would be
pd.DataFrame({'id' : ['1','2','3','4','5'], 'group' : ['1','1','2','1','2'],
'state' : ['True','False','False','True','True'], 'avg_state' : [0.66,0.66,0.5,0.66,0.5] ,value' : [11,12,5,8,3]})