def groupMeanValue(group):
    group['value'] = group['value'].fillna(group['value'].mean())
return group
dft = df.groupby('name').transform(groupMeanValue)
Pandas: filling missing values by mean in each group