Groupby.agg

Obtain data aggregate per groups for each column

danfo.Groupby.agg(kwargs) [source]

Parameters
Type
Description
Default

ops

Object

keys are column names and values are aggregation operator

{}

Return: DataFrame

Examples

Aggregation using one aggregate operator per column

  1. Assigning mean and sum aggregate to different column

const dfd = require("danfojs-node")


let data ={'A': ['foo', 'bar', 'foo', 'bar',
                'foo', 'bar', 'foo', 'foo'],
           'B': ['one', 'one', 'two', 'three',
                'two', 'two', 'one', 'three'],
           'C': [1,3,2,4,5,2,6,7],
           'D': [3,2,4,1,5,6,7,8]
        }

let df = new dfd.DataFrame(data)

let grp = df.groupby(["A"])
grp.agg({C:"mean",D:"sum"}).print()
  1. Mean and Sum aggregate on dataframe grouped by two column

Aggregation using two or more aggregate operator per column

Assigning mean and sum, min, std, count aggregate to different column

Last updated

Was this helpful?