Reputation: 83
I have a python pandas dataframe like:
a b
1 5
3 6
1 7
2 8
2 34
3 35
1 54
3 123
4 2353
... ....
I want get the mean of value in b when a has different value. For example, when a = 1, b = 5, 7, 54, so the mean(a=1) = (5 + 7 + 54)/3; when a = 2, b = 8, 34, so the mean(a=2) = (8 + 34)/2;
my try is
aaa = []
for v in df['a']:
aaa.append(np.mean(df['b'])
print (aaa)
but it's not right. hope you can help me. thank you !
Upvotes: 6
Views: 9146