DataFrame.apply_map
Apply a function to a Dataframe values element-wise.
danfo.DataFrame.apply_map(callable, options) [source]
Parameters
Type
Description
Default
callable
Function
Function to apply to each column or row
options
Object
axis: 0 or 1. If 0, compute the power column-wise, if 1, row-wise
{axis: 1}
Returns:
return DataFrame

Examples

Apply a function to all values in a DataFrame

Note that the specified function passed to apply will be called with each element in the DataFrame. If you need to apply a function across an axis, then use the apply function.
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = {
4
short_name: ["NG", "GH", "EGY", "SA"],
5
long_name: ["Nigeria", "Ghana", "Eqypt", "South Africa"]
6
}
7
let df = new dfd.DataFrame(data)
8
9
function lower(x) {
10
return `${x}`.toLowerCase()
11
}
12
13
let df_new = df.apply_map(lower)
14
df_new.print()
Copied!
1
Copied!
Output
1
╔════════════╤═══════════════════╤═══════════════════╗
2
║ │ short_name │ long_name ║
3
╟────────────┼───────────────────┼───────────────────╢
4
║ 0 │ ng │ nigeria ║
5
╟────────────┼───────────────────┼───────────────────╢
6
║ 1 │ gh │ ghana ║
7
╟────────────┼───────────────────┼───────────────────╢
8
║ 2 │ egy │ eqypt ║
9
╟────────────┼───────────────────┼───────────────────╢
10
║ 3 │ sa │ south africa ║
11
╚════════════╧═══════════════════╧═══════════════════╝
Copied!
Last modified 17d ago