danfo.DataFrame.rename(kwargs) [source]
Parameters | Type | Description | Default |
kwargs | Object | { mapper: Object of labels and transformations to apply to that axis’ values. axis: row=0, columns=1. inplace: specify whether to perform the operation to the row/column with/without creating a new DataFrame } | {axis: 1, inplace:false} |
Returns:
return DataFrame
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],"B": [34, -4, 5],"C": [20, 2, 3, 30] }let df = new dfd.DataFrame(data)df.rename({ mapper: {"A": "new_name"},inplace: true })df.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ new_name │ B │ C ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ -20 │ 34 │ 20 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 1 │ 30 │ -4 │ 20 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 2 │ 47.3 │ 5 │ 30 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
const dfd = require("danfojs-node")let data = { "A": [-20, 30, 47.3],"B": [34, -4, 5, 6],"C": [20, 2, 3, 30] }let df = new dfd.DataFrame(data)df = df.rename({ mapper: {"A": "new_name", "C": "new_c"}})df.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ new_name │ B │ new_c ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ -20 │ 34 │ 20 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 1 │ 30 │ -4 │ 20 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 2 │ 47.3 │ 5 │ 30 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
const dfd = require("danfojs-node")let data = { "A": [-20, 30, 47.3],"B": [34, -4, 5, 6],"C": [20, 2, 3, 30] }let df = new dfd.DataFrame(data, {index: ["a", "b", "a"]})df = df.rename({ mapper: {"a": 0}, axis: 0})df.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ A │ B │ C ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ -20 │ 34 │ 20 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ b │ 30 │ -4 │ 20 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ 47.3 │ 5 │ 30 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝