h2oai / h2oai/datatable

Custom Group By Functions

Open
#3,296 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
164
Avg merge
7h 31m
Merged PRs (30d)
1

Description

Following the documentation, you can get the count per group using:
```
x[:, { 'count': dt.count() }, by('id') ]
```
When trying to also include the percentile of a column by group, the `np.percentile()` function does not work
```
x[:, { 'count': dt.count(), 'percentile': np.percentile(f.my_col, 1) }, by('id') ]
```
How does the `by` operator handle the `f.my_col` selector? In R's `data.table` , you can basically apply any function that takes a vector as an input. so using `np.percentile` on the `f.my_col` would work. and the resulting table would be something like:
id | count | percentile
--- | ------ | ---------
0 | 10 | 5
1 | 30 | 10
.... | .... | ....

i've seen this issue which has a similar request for quantiles: https://github.com/h2oai/datatable/issues/3165

How would I apply a custom function ( or one like `np.percentile()`) to the subset, or a column subset in the `by`?
do all functions need to be made "group-aware" to use `by`?
Does this make any custom-function by group impossible to do? Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.