Series.dropDuplicates
Remove duplicate rows
danfo.Series.dropDuplicates(options)
Parameters
Type
Description
Default
options
Object
keep: "first"
"last", which duplicate value to keep. Defaults to "first". inplace: Boolean indicating whether to perform the operation in-place or not. Defaults to false
Returns: Series
Examples

Drop duplicate by keeping the first occurrence of the duplicate value

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [10, 45, 56, 10, 23, 20, 10, 10]
4
let sf = new dfd.Series(data1)
5
let sf_drop = sf.dropDuplicates()
6
7
sf_drop.print()
Copied!
Output
1
╔═══╤════╗
2
║ 0 │ 10 ║
3
╟───┼────╢
4
║ 1 │ 45 ║
5
╟───┼────╢
6
║ 2 │ 56 ║
7
╟───┼────╢
8
║ 4 │ 23 ║
9
╟───┼────╢
10
║ 5 │ 20 ║
11
╚═══╧════╝
Copied!

Drop duplicate and keep only the last duplicated value

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [10, 45, 56, 10, 23, 20, 10, 10]
4
let sf = new dfd.Series(data1)
5
let sf_drop = sf.dropDuplicates({ keep: "last" })
6
7
sf_drop.print()
Copied!
Output
1
╔═══╤════╗
2
║ 1 │ 45 ║
3
╟───┼────╢
4
║ 2 │ 56 ║
5
╟───┼────╢
6
║ 4 │ 23 ║
7
╟───┼────╢
8
║ 5 │ 20 ║
9
╟───┼────╢
10
║ 7 │ 10 ║
11
╚═══╧════╝
Copied!

Remove duplicate value in-place

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = ["A", "A", "A", "B", "B", "C", "C", "D"]
4
let sf = new dfd.Series(data1)
5
sf.dropDuplicates({ inplace: true })
6
7
sf.print()
Copied!
Output
1
╔═══╤═══╗
2
║ 0 │ A ║
3
╟───┼───╢
4
║ 3 │ B ║
5
╟───┼───╢
6
║ 5 │ C ║
7
╟───┼───╢
8
║ 7 │ D ║
9
╚═══╧═══╝
Copied!