Powered By GitBook
Series.drop_duplicates
Remove duplicate rows
danfo.Series.drop_duplicates(options) [source]
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
{
inplace: 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.drop_duplicates()
6
7
sf_drop.print()
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 0 │ 10 ║
5
╟───┼──────────────────────╢
6
║ 1 │ 45 ║
7
╟───┼──────────────────────╢
8
║ 2 │ 56 ║
9
╟───┼──────────────────────╢
10
║ 4 │ 23 ║
11
╟───┼──────────────────────╢
12
║ 5 │ 20 ║
13
╚═══╧══════════════════════╝
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.drop_duplicates({keep:"last"})
6
7
sf_drop.print()
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 1 │ 45 ║
5
╟───┼──────────────────────╢
6
║ 2 │ 56 ║
7
╟───┼──────────────────────╢
8
║ 4 │ 23 ║
9
╟───┼──────────────────────╢
10
║ 5 │ 20 ║
11
╟───┼──────────────────────╢
12
║ 7 │ 10 ║
13
╚═══╧══════════════════════╝
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.drop_duplicates({inplace:true})
6
7
sf.print()
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 0 │ A ║
5
╟───┼──────────────────────╢
6
║ 3 │ B ║
7
╟───┼──────────────────────╢
8
║ 5 │ C ║
9
╟───┼──────────────────────╢
10
║ 7 │ D ║
11
╚═══╧══════════════════════╝
Copied!
Last modified 24d ago