Is there a way to implement a weighted average using the groupby function? #2969
Answered
by
st-pasha
franlane94
asked this question in
Q&A
-
Hi all, I was wondering whether there is a neat way to implement a weighted mean when using the groupby function. I would achieve this in Pandas by applying a function when grouping. However, I can't see a way to do this using datatable. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
st-pasha
Jun 2, 2021
Replies: 1 comment
-
Formula |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
st-pasha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Formula
dt.sum(f.X * f.weight) / dt.sum(f.weight)
will compute weighted average of a columnX
, and you can use it either with or without a groupby.