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.replace
Replaces values in a DataFrame with specified values
danfo.DataFrame.
replace
(oldValue, newValue, options)
Parameters
Type
Description
Default
oldValue
String, boolean, Number
The value you want to replace
newValue
String, boolean, Number
The new value you want to replace the old value with
options
Object
columns:
Array
.
An array of column names to replace, If not specified, replace all columns.
inplace
: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{inplace: false}
Examples
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_rep
=
df
.
replace
(
10
,
-
999
,
{
columns
:
[
"Col1"
]
})
10
11
df_rep
.
print
()
12
13
Copied!
1
Copied!
Output
1
╔═══╤═══════════════════╤═══════════════════╗
2
║ │ Col1 │ Col2 ║
3
╟───┼───────────────────┼───────────────────╢
4
║ 0 │ -999 │ 23 ║
5
╟───┼───────────────────┼───────────────────╢
6
║ 1 │ 45 │ 20 ║
7
╟───┼───────────────────┼───────────────────╢
8
║ 2 │ 56 │ 10 ║
9
╟───┼───────────────────┼───────────────────╢
10
║ 3 │ -999 │ 24 ║
11
╚═══╧═══════════════════╧═══════════════════╝
Copied!
If a column name is not specified,
replace
works on all columns:
Node
Browser
1
const
dfd
=
require
(
"danfojs-node"
)
2
3
let
data
=
[[
"A"
,
"A"
,
"A"
,
"B"
],
[
"B"
,
"C"
,
"C"
,
"D"
]]
4
let
df
=
new
dfd
.
DataFrame
(
data
)
5
//replace value in all column
6
let
df_rep
=
df
.
replace
(
"A"
,
"BOY"
)
7
8
df_rep
.
print
()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
2
║ │
0
│
1
│
2
│
3
║
3
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
4
║
0
│
BOY
│
BOY
│
BOY
│
B
║
5
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
6
║
1
│
B
│
C
│
C
│
D
║
7
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
Copied!
Previous
DataFrame.eq
Next
Configuration Options
Last modified
3mo ago
Copy link
Contents
Examples