danfo.DataFrame.replace(kwargs) [source]
Parameters | Type | Description | Default |
kwargs | Object | {replace: int, float, str. The value to replace. with: Int, float, str. The new value to replace with. in: Array. An array of column names to replace, If not specified, replace all columns. } | |
Returns:
return DataFrame
const dfd = require("danfojs-node")let data = {"Col1": [10, 45, 56, 10],"Col2": [23, 20, 10, 24]}let df = new dfd.DataFrame(data)let df_rep = df.replace({ "replace": 10, "with": -999, "in": ["Col1"] })df_rep.print()
╔═══╤═══════════════════╤═══════════════════╗║ │ Col1 │ Col2 ║╟───┼───────────────────┼───────────────────╢║ 0 │ -999 │ 23 ║╟───┼───────────────────┼───────────────────╢║ 1 │ 45 │ 20 ║╟───┼───────────────────┼───────────────────╢║ 2 │ 56 │ 10 ║╟───┼───────────────────┼───────────────────╢║ 3 │ -999 │ 24 ║╚═══╧═══════════════════╧═══════════════════╝
By not specifying a column, the replace works on all columns
const dfd = require("danfojs-js")let data = [["A", "A", "A", "B"], ["B", "C", "C", "D"]]let df = new dfd.DataFrame(data)//replace value in all columnlet df_rep = df.replace({ "replace": "A", "with": "boy" })df_rep.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ 0 │ 1 │ 2 │ 3 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ boy │ boy │ boy │ B ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 1 │ B │ C │ C │ D ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝