Note
Pandas (26) 본문
728x90
How to get the mean of a series grouped by another series?
# Input
fruit = pd.Series(np.random.choice(['apple', 'banana', 'carrot'], 10))
weights = pd.Series(np.linspace(1, 10, 10))
# Solution
weights.groupby(fruit).mean()
# output
apple 7.4
banana 2.0
carrot 6.0
dtype: float64
'Pandas' 카테고리의 다른 글
Pandas (28) (0) | 2022.08.20 |
---|---|
Pandas (27) (0) | 2022.08.19 |
Pandas (25) (0) | 2022.08.16 |
Pandas (24) (0) | 2022.08.15 |
Pandas (23) (0) | 2022.08.14 |
Comments