Danfo.js
Getting Started
API Reference
Contributing Guide
Github
Search…
Danfo.js Documentation
Getting Started
API reference
General Functions
Input/Output
Series
Dataframe
Creating a DataFrame
DataFrame.sortIndex
DataFrame.append
DataFrame.nUnique
DataFrame.tensor
DataFrame.print
DataFrame.toCSV
DataFrame.toJSON
DataFrame.toExcel
DataFrame.sortValues
DataFrame.setIndex
DataFrame.resetIndex
DataFrame.rename
DataFrame.drop
DataFrame.asType
DataFrame.shape
DataFrame.axis
DataFrame.ndim
DataFrame.values
DataFrame.selectDtypes
DataFrame.ctypes
DataFrame.index
DataFrame.loc
DataFrame.iloc
DataFrame.at
DataFrame.iat
DataFrame.head
DataFrame.tail
DataFrame.sample
DataFrame.add
DataFrame.sub
DataFrame.mul
DataFrame.div
DataFrame.pow
DataFrame.mod
DataFrame.mean
DataFrame.median
DataFrame.min
DataFrame.max
DataFrame.std
DataFrame.var
DataFrame.count
DataFrame.round
DataFrame.cumSum
DataFrame.cumMin
DataFrame.cumMax
DataFrame.cumProd
DataFrame.copy
DataFrame.describe
DataFrame.sum
DataFrame.abs
DataFrame.query
DataFrame.addColumn
DataFrame.groupby
DataFrame.column
DataFrame.fillNa
DataFrame.isNa
DataFrame.dropNa
DataFrame.apply
DataFrame.applyMap
DataFrame.It
DataFrame.gt
DataFrame.le
DataFrame.ge
DataFrame.ne
DataFrame.eq
DataFrame.replace
Configuration Options
Plotting
Groupby
User Guides
Building Data Driven Applications with Danfo.js - Book
Contributing Guide
Release Notes
Powered By
GitBook
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
Node
Browser
1
const
dfd
=
require
(
"danfojs-node"
)
2
3
let
data
=
{
4
"Col1"
:
[
10
,
45
,
56
,
10
],
5
"Col2"
:
[
23
,
20
,
10
,
24
]
6
}
7
let
df
=
new
dfd
.
DataFrame
(
data
)
8
9
let
df_new
=
df
.
sub
(
2
)
10
11
df_new
.
print
()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╗
2
║ │ Col1 │ Col2 ║
3
╟────────────┼───────────────────┼───────────────────╢
4
║ 0 │ 8 │ 21 ║
5
╟────────────┼───────────────────┼───────────────────╢
6
║ 1 │ 43 │ 18 ║
7
╟────────────┼───────────────────┼───────────────────╢
8
║ 2 │ 54 │ 8 ║
9
╟────────────┼───────────────────┼───────────────────╢
10
║ 3 │ 8 │ 22 ║
11
╚════════════╧═══════════════════╧═══════════════════╝
Copied!
Subtraction of
Series from
DataFrame along axis 0
Node
Browser
1
const
dfd
=
require
(
"danfojs-node"
)
2
3
let
data
=
{
4
"Col1"
:
[
1
,
4
,
5
,
1
],
5
"Col2"
:
[
3
,
2
,
0
,
4
]
6
}
7
8
let
df
=
new
dfd
.
DataFrame
(
data
)
9
let
sf
=
new
dfd
.
Series
([
4
,
5
])
10
11
let
df_new
=
df
.
sub
(
sf
,
{
axis
:
1
})
12
13
df_new
.
print
()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╗
2
║ │ Col1 │ Col2 ║
3
╟────────────┼───────────────────┼───────────────────╢
4
║ 0 │ -3 │ -2 ║
5
╟────────────┼───────────────────┼───────────────────╢
6
║ 1 │ 0 │ -3 ║
7
╟────────────┼───────────────────┼───────────────────╢
8
║ 2 │ 1 │ -5 ║
9
╟────────────┼───────────────────┼───────────────────╢
10
║ 3 │ -3 │ -1 ║
11
╚════════════╧═══════════════════╧═══════════════════╝
Copied!
Subtraction of DataFrame from another DataFrame
Node
Browser
1
const
dfd
=
require
(
"danfojs"
)
2
3
let
data
=
{
"Col1"
:
[
1
,
4
,
5
,
0
],
4
"Col2"
:
[
2
,
0
,
1
,
4
]}
5
6
let
data2
=
{
"new_col1"
:
[
1
,
5
,
20
,
10
],
7
"new_Col2"
:
[
20
,
2
,
1
,
2
]}
8
9
let
df
=
new
dfd
.
DataFrame
(
data
)
10
let
df2
=
new
dfd
.
DataFrame
(
data2
)
11
12
let
df_new
=
df
.
sub
(
df2
)
13
14
df_new
.
print
()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╗
2
║ │ Col1 │ Col2 ║
3
╟────────────┼───────────────────┼───────────────────╢
4
║ 0 │ 0 │ -18 ║
5
╟────────────┼───────────────────┼───────────────────╢
6
║ 1 │ -1 │ -2 ║
7
╟────────────┼───────────────────┼───────────────────╢
8
║ 2 │ -15 │ 0 ║
9
╟────────────┼───────────────────┼───────────────────╢
10
║ 3 │ -10 │ 2 ║
11
╚════════════╧═══════════════════╧═══════════════════╝
Copied!
Subtraction of Array from DataFrame along axis 0
Node
Browser
1
const
dfd
=
require
(
"danfojs-node"
)
2
3
let
data
=
{
4
"Col1"
:
[
10
,
45
,
56
,
10
],
5
"Col2"
:
[
23
,
20
,
10
,
24
]
6
}
7
8
let
df
=
new
dfd
.
DataFrame
(
data
)
9
let
val
=
[
2
,
2
,
2
,
2
]
10
11
let
df_new
=
df
.
sub
(
val
,
{
axis
:
0
})
12
13
df_new
.
print
()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╗
2
║ │ Col1 │ Col2 ║
3
╟────────────┼───────────────────┼───────────────────╢
4
║ 0 │ 8 │ 21 ║
5
╟────────────┼───────────────────┼───────────────────╢
6
║ 1 │ 43 │ 18 ║
7
╟────────────┼───────────────────┼───────────────────╢
8
║ 2 │ 54 │ 8 ║
9
╟────────────┼───────────────────┼───────────────────╢
10
║ 3 │ 8 │ 22 ║
11
╚════════════╧═══════════════════╧═══════════════════╝
Copied!
Subtraction works inplace
Node
Browser
1
const
dfd
=
require
(
"danfojs-node"
)
2
3
let
data
=
{
4
"Col1"
:
[
10
,
45
,
56
,
10
],
5
"Col2"
:
[
23
,
20
,
10
,
24
]
6
}
7
8
let
df
=
new
dfd
.
DataFrame
(
data
)
9
let
val
=
[
2
,
2
,
2
,
2
]
10
11
df
.
sub
(
val
,
{
axis
:
0
,
inplace
:
true
})
12
13
df
.
print
()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╗
2
║ │ Col1 │ Col2 ║
3
╟────────────┼───────────────────┼───────────────────╢
4
║ 0 │ 8 │ 21 ║
5
╟────────────┼───────────────────┼───────────────────╢
6
║ 1 │ 43 │ 18 ║
7
╟────────────┼───────────────────┼───────────────────╢
8
║ 2 │ 54 │ 8 ║
9
╟────────────┼───────────────────┼───────────────────╢
10
║ 3 │ 8 │ 22 ║
11
╚════════════╧═══════════════════╧═══════════════════╝
Copied!
Previous
DataFrame.add
Next
DataFrame.mul
Last modified
4mo ago
Copy link
Contents
Examples
Subtraction of scalar from DataFrame along default axis 1
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