3

Is it possible to "apply" a user function to a python datatable after groupby?

For example:

import datatable as dt
from datatable import f, by, sum
df = dt.Frame(SYM=['A','A','A','B','B'], xval=[1.1,1.2,2.3,2.4,2.5])
print(df[:, sum(f.xval), by(f.SYM)])

This works. But I would like to replace the "sum" function with a user function defined using:

def func(x):
    # do some operations here; e.g. ranking
    y = x
    return(y)    

Is this possible? Can you please provide an example (may be using numpy.rank inside func above)?

Pasha
  • 6,298
  • 2
  • 22
  • 34
balaks
  • 215
  • 1
  • 8

0 Answers0