You can set and select column value
by DataFrame.loc
:
df.loc[df['column'] == 'c', 'value'] = df.loc[df['column'] == 'a', 'value'].mean()
print (df)
column value
0 a 0.000000
1 b 1.000000
2 a 2.000000
3 b 3.000000
4 b 4.000000
5 a 5.000000
6 b 6.000000
7 c 2.333333
8 d 8.000000
Or if need test multiple values use Series.isin
:
df.loc[df['column'] == 'c', 'value'] = df.loc[df['column'].isin(['a','b']), 'value'].mean()
print (df)
column value
0 a 0.000000
1 b 1.000000
2 a 2.000000
3 b 3.000000
4 b 4.000000
5 a 5.000000
6 b 6.000000
7 c 3.333333
8 d 8.000000
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…