Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

[QUESTION] Is there a way to add multiple aggregations to grouped dataframe? #107

Open
olgacarpenter opened this issue May 5, 2020 · 3 comments · May be fixed by #127
Open

[QUESTION] Is there a way to add multiple aggregations to grouped dataframe? #107

olgacarpenter opened this issue May 5, 2020 · 3 comments · May be fixed by #127
Labels

Comments

@olgacarpenter
Copy link

Is there a way to add multiple aggregations to grouped dataframe?
I would like to group the data and aggregate two different columns.

@lobanov
Copy link

lobanov commented Aug 11, 2020

There is no API for this, but I found you could achieve this with a bit extra work in exactly the same way aggregate(...) function works internally:

// assuming that sourceDf has columns ['key', 'col1', 'col2']
const groupedDf = sourceDf.groupBy('key');
const complexAggregateDf = new DataFrame([...groups].map(({groupKey, group}) => ({
  ...groupKey,
  'sum1': group.stat.sum('col1'),
  'sum2': group.stat.sum('col2'),
}), [...groupedDf.on, 'sum1', 'sum2']);```

@adapptative
Copy link

If somebody is wondering how to get this "groups" variable, I was able to get it by doing that:

const __groups__ = require('../node_modules/dataframe-js/lib/symbol').__groups__;
const groupedDf = sourceDf.groupBy('key');
const complexAggregateDf = new DataFrame(Object.values(groupedDf[__groups__]).map(({groupKey, group}) => ({
  ...groupKey,
  'sum1': group.stat.sum('col1'),
  'sum2': group.stat.sum('col2'),
}), [...groupedDf.on, 'sum1', 'sum2']);

@romainhild
Copy link

How would I do that from client-side ? I can't get the groups or __groups__ variable.

brendanashworth added a commit to brendanashworth/dataframe-js that referenced this issue Jun 29, 2021
@brendanashworth brendanashworth linked a pull request Jun 29, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants