You an use operator.methodcaller for this:
from operator import methodcaller
df = pd.DataFrame({'a': range(11)})
def foo(df, col, method):
return methodcaller(method)(df[col])
res_sum = foo(df, 'a', 'sum') # 55
res_avg = foo(df, 'a', 'mean') # 5.0
The reason for your error is you are trying to pass the result of a called function with no arguments, one that happens to require arguments to work.
The benefit of passing strings is you rely on tried-and-tested methods built into the Pandas framework, e.g. pd.Series.sum, pd.Series.mean, etc. While you can attempt to use Python built-ins and NumPy functions directly with Pandas series, you may find discrepancies versus what you might expect. Stick with documented Pandas methods where possible.
return dataframe.groupby(col_name).agg(method1).