shortcuts/encoding.ts
2024-09-25 21:19:10 +02:00

15 lines
361 B
TypeScript

import pl from "npm:nodejs-polars";
export function oneHotEncoding(dataframe) {
let df = pl.DataFrame();
for (const columnName of dataframe.columns) {
const column = dataframe[columnName];
if (!column.isNumeric()) {
df = df.hstack(column.toDummies());
} else {
df = df.hstack(dataframe.select(columnName));
}
}
return df;
}