Series.dropDuplicates

Remove duplicate rows

danfo.Series.dropDuplicates(options)

ParametersTypeDescriptionDefault

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

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()
╔═══╤════╗
║ 0 │ 10 ║
╟───┼────╢
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╚═══╧════╝

Drop duplicate and keep only the last duplicated value

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()
╔═══╤════╗
║ 1 │ 45 ║
╟───┼────╢
║ 2 │ 56 ║
╟───┼────╢
║ 4 │ 23 ║
╟───┼────╢
║ 5 │ 20 ║
╟───┼────╢
║ 7 │ 10 ║
╚═══╧════╝

Remove duplicate value in-place

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()
╔═══╤═══╗
║ 0 │ A ║
╟───┼───╢
║ 3 │ B ║
╟───┼───╢
║ 5 │ C ║
╟───┼───╢
║ 7 │ D ║
╚═══╧═══╝

Last updated