Is it possible to directly compute the product (or for example sum) of two columns without using
grouped.apply(lambda x: (x.a*x.b).sum()
df['helper'] = df.a*df.b
grouped.apply(lambda x: (x.a*x.b).sum()/(df.b).sum())
I want to eventually build an embedded array expression evaluator (Numexpr on steroids) to do things like this. Right now we're working with the limitations of Python-- if you implemented a Cython aggregator to do
(x * y).sum() then it could be connected with groupby, but ideally you could write the Python expression as a function:
def weight_sum(x, y): return (x * y).sum()
and that would get "JIT-compiled" and be about as fast as groupby(...).sum(). What I'm describing is a pretty significant (many month) project. If there were a BSD-compatible APL implementation I might be able to do something like the above quite a bit sooner (just thinking out loud).