DataFrame.median

Return the median of the values for the requested axis.

danfo.DataFrame.median(options)

ParametersTypeDescriptionDefault

options

Object

axis: 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1

{ axis: 1 }

Examples

Computes the median of values along default axis 1 (column)

const dfd = require("danfojs-node")

data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]]
cols = ["A", "B", "C"]

let df = new dfd.DataFrame(data)
df.print()
df.median().print()
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 11                │ 20                │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 1                 │ 15                │ 6                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 2                 │ 30                │ 40                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 2                 │ 89                │ 78                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔═══╤════╗
║ 0 │ 11 ║
╟───┼────╢
║ 1 │ 6  ║
╟───┼────╢
║ 2 │ 30 ║
╟───┼────╢
║ 3 │ 78 ║
╚═══╧════╝

Computes the median of values along row axis (0)

const dfd = require("danfojs-node")


let data = [[11, 20, 3], [1, 15, 6], [2, 30, 40], [2, 89, 78]]
let cols = ["A", "B", "C"]

let df = new dfd.DataFrame(data, { columns: cols })
df.print()
df.median({ axis: 0 }).print()
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ A                 │ B                 │ C                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0          │ 11                │ 20                │ 3                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1          │ 1                 │ 15                │ 6                 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2          │ 2                 │ 30                │ 40                ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3          │ 2                 │ 89                │ 78                ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔═══╤════╗
║ A │ 2  ║
╟───┼────╢
║ B │ 25 ║
╟───┼────╢
║ C │ 23 ║
╚═══╧════╝

Last updated