I have a dictionary:
dict = { "A": ("a", "mean"),
"B": ("b", "sum")}
I want to use the following function for each of the keys:
for i in dict.keys():
df.groupby(i)[dict[i][0]].sum()
or
df.groupby(i)[dict[i][0]].mean()
How can I replace hardcoded "sum" or "mean", so it uses what is given in the dictionary? Something like this:
df.groupby(i)[dict[i][0]].dict[i][1]()