danfo.getDummies
Convert categorical variable into dummy/indicator variables.
Parameters
Type
Description
Default
Examples
Convert Series to Dummy codes
const dfd = require("danfojs-node")
let datasf = ['pear', 'mango', "pawpaw", "mango", "bean"]
let sf1 = new dfd.Series(datasf)
let dum_df = dfd.getDummies(sf1, { prefix: "fruit" })
dum_df.print()╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ fruit_pear │ fruit_mango │ fruit_pawpaw │ fruit_bean ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 1 │ 0 │ 0 │ 0 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 0 │ 1 │ 0 │ 0 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 0 │ 0 │ 1 │ 0 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 3 │ 0 │ 1 │ 0 │ 0 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 4 │ 0 │ 0 │ 0 │ 1 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝Convert all categorical columns in a DataFrame to Dummy codes
Convert a specific column in a DataFrame to Dummy codes
Last updated