DataFrame.groupby

Group DataFrame using a mapper or by a Series of columns.

danfo.DataFrame.groupby(columns) [source]

Parameters

Type

Description

Default

columns

Array

The names of a column(s) in the DataFrame to group by

Returns:

return DataFrame.groups

Examples

Select a single column from a DataFrame

Node
Browser
Node
const dfd = require("danfojs-node")
let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]]
let cols = ["A", "B", "C"]
let df = new DataFrame(data, { columns: cols })
let group_df = df.groupby(["A"]);
group_df.col_dict
Browser
Output
Output
╔═══╤══════════════════════╗
║ │ Name ║
╟───┼──────────────────────╢
║ 0 │ Apples ║
╟───┼──────────────────────╢
║ 1 │ Mango ║
╟───┼──────────────────────╢
║ 2 │ Banana ║
╟───┼──────────────────────╢
║ 3 │ NaN ║
╚═══╧══════════════════════╝
╔═══╤══════════════════════╗
║ │ Name ║
╟───┼──────────────────────╢
║ 0 │ Apples ║
╟───┼──────────────────────╢
║ 1 │ Mango ║
╟───┼──────────────────────╢
║ 2 │ Banana ║
╟───┼──────────────────────╢
║ 3 │ NaN ║
╚═══╧══════════════════════╝

To select more than one column with specific rows, you can use any of the following: DataFrame.loc, DataFrame.iloc or DataFrame.query