DataFrame.sub

Get Subtraction of dataframe and other, element-wise (binary operator sub).

danfo.DataFrame.sub(other, option)

Parameters
Type
Description
Default

other

DataFrame, Series, Array or Scalar

Object to subtract

option

Object

{

axis: 0 for row, 1 for column.

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

}

{ axis: 1, inplace: false }

Examples

Subtraction of scalar from DataFrame along default axis 1

const dfd = require("danfojs-node")

let data = {
    "Col1": [10, 45, 56, 10],
    "Col2": [23, 20, 10, 24]
}
let df = new dfd.DataFrame(data)

let df_new = df.sub(2)

df_new.print()
╔════════════╤═══════════════════╤═══════════════════╗
║            │ Col1              │ Col2              ║
╟────────────┼───────────────────┼───────────────────╢
║ 0          │ 8                 │ 21                ║
╟────────────┼───────────────────┼───────────────────╢
║ 1          │ 43                │ 18                ║
╟────────────┼───────────────────┼───────────────────╢
║ 2          │ 54                │ 8                 ║
╟────────────┼───────────────────┼───────────────────╢
║ 3          │ 8                 │ 22                ║
╚════════════╧═══════════════════╧═══════════════════╝

Subtraction of Series from DataFrame along axis 0

Subtraction of DataFrame from another DataFrame

Subtraction of Array from DataFrame along axis 0

Subtraction works inplace

Last updated