Groupby.col

Obtain the column(s) per groups

danfo.Groupby.col(col_names) [source]

Parameters
Type
Description
Default

col_names

Array

List of column

Returns: Groupby Data structure

Note: This is similar to pandas df.groupby(["column"])["colNames"]

Examples

Obtain the column to perform group aggregate operation on

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"])

//select single column
let grpColumnC = grp.col(["C"])

// convert grouop internal data to dataFrame
grpColumnC.apply(x=> x).print()

//select multiple column
let grpColumnBD = grp.col(["B", "D"])

grpColumnBD.apply(x=> x).print()

Apparently the output are not that useful unless you perform some operations like max(), count() and the likes.

Last updated

Was this helpful?