weigted average in pandas
g = df.groupby('Date')
df.value / g.value.transform("sum") * df.wt
4.5
2
In [11]: g = df.groupby('Date')
In [12]: df.value / g.value.transform("sum") * df.wt
Out[12]:
0 0.125000
1 0.250000
2 0.416667
3 0.277778
4 0.444444
dtype: float64
Thank you!
2
0
Are there any code examples left?
New code examples in category Python