I'm trying to apply multiple functions to different columns in pandas. My dataframe consists of over 10M rows and over 100K groups. I'm trying to similar operations as in this (Example below), but it takes a long time. I tried using dask, but that didn't help either.
Any suggestions on how to improve this example below?
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.rand(4,4), columns=list('abcd'))
df['group'] = [0, 0, 1, 1]
def f(x):
d = {}
d['a_sum'] = x['a'].sum()
d['a_max'] = x['a'].max()
d['b_mean'] = x['b'].mean()
d['c_d_prodsum'] = (x['c'] * x['d']).sum()
return pd.Series(d, index=['a_sum', 'a_max', 'b_mean', 'c_d_prodsum'])
df.groupby('group').apply(f)