DataFrame.drop

Drop specified labels from rows or columns.Remove rows or columns by specifying label names and corresponding axis.

danfo.DataFrame.drop(options)

Returns:

**** return DataFrame

Examples

Drop columns by specifying the names

By setting inplace to true, the original DataFrame is modified and nothing is returned. To not modify the original DataFrame and return a new one, set inplace to false or leave it as default.

const dfd = require("danfojs-node")

let data = { "A": [-20, 30, 47.3, -20],
             "B": [34, -4, 5, 6] ,
             "C": [20, 20, 30, 30],
             "D": ["a", "b", "c", "c"] }

let df = new dfd.DataFrame(data)
df.drop({ columns: ["C", "B"], inplace: true });
df.print()
╔═══╤═══════════════════╤═══════════════════╗
║   │ A                 │ D                 ║
╟───┼───────────────────┼───────────────────╢
║ 0 │ -20               │ a                 ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ 30                │ b                 ║
╟───┼───────────────────┼───────────────────╢
║ 2 │ 47.3              │ c                 ║
╟───┼───────────────────┼───────────────────╢
║ 3 │ -20               │ c                 ║
╚═══╧═══════════════════╧═══════════════════╝

Drop rows by specifying int labels/index

const dfd = require("danfojs-node")

let data = {
    "A": [-20, 30, 47.3, -20],
    "B": [34, -4, 5, 6],
    "C": [20, 20, 30, 30],
    "D": ["a", "b", "c", "c"]
}

let df = new dfd.DataFrame(data)
df.drop({ index: [0, 2], inplace: true });
df.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30                │ -4                │ 20                │ b                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ -20               │ 6                 │ 30                │ c                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

Drop rows by specifying string labels/index

const dfd = require("danfojs-node")

let data = { "A": [-20, 30, 47.3, -20],
             "B": [34, -4, 5, 6] ,
             "C": [20, 20, 30, 30],
             "D": ["a", "b", "c", "c"] }

let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]})
df.drop({ index: ["a", "c"], inplace: true });
df.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║   │ A                 │ B                 │ C                 │ D                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b │ 30                │ -4                │ 20                │ b                 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ d │ -20               │ 6                 │ 30                │ c                 ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

Last updated