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
const dfd = require("danfojs-node")
let data1 = [10, 45, 56, 10, 23, 20, 10, 10]
let sf = new dfd.Series(data1)
let sf_drop = sf.dropDuplicates()
sf_drop.print()
Output
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╚═══╧════╝

Drop duplicate and keep only the last duplicated value

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

Remove duplicate value in-place

Node
const dfd = require("danfojs-node")
let data1 = ["A", "A", "A", "B", "B", "C", "C", "D"]
let sf = new dfd.Series(data1)
sf.dropDuplicates({ inplace: true })
sf.print()
Output
╔═══╤═══╗
║ 0 │ A ║
╟───┼───╢
║ 3 │ B ║
╟───┼───╢
║ 5 │ C ║
╟───┼───╢
║ 7 │ D ║
╚═══╧═══╝
Copy link
On this page
Drop duplicate by keeping the first occurrence of the duplicate value
Drop duplicate and keep only the last duplicated value
Remove duplicate value in-place