DataFrame.drop
Drop specified labels from rows or columns.Remove rows or columns by specifying label names and corresponding axis.
danfo.DataFrame.drop(options)
Parameters
Type
Description
Default
options
Object
{
columns: Array of column names to drop.
index: Array of index labels to drop.
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
}
{**inplace:**false}
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.
Node
Browser
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()
Output
╔═══╤═══════════════════╤═══════════════════╗
║ │ A │ D ║
╟───┼───────────────────┼───────────────────╢
║ 0 │ -20 │ a ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ 30 │ b ║
╟───┼───────────────────┼───────────────────╢
║ 2 │ 47.3 │ c ║
╟───┼───────────────────┼───────────────────╢
║ 3 │ -20 │ c ║
╚═══╧═══════════════════╧═══════════════════╝

Drop rows by specifying int labels/index

Node
Browser
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()
Output
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C │ D ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30 │ -4 │ 20 │ b ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ -20 │ 6 │ 30 │ c ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

Drop rows by specifying string labels/index

Node
Browser
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()
Output
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C │ D ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b │ 30 │ -4 │ 20 │ b ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ d │ -20 │ 6 │ 30 │ c ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
Copy link
On this page
Examples
Drop columns by specifying the names
Drop rows by specifying int labels/index
Drop rows by specifying string labels/index