shortcuts/encoding.ts

15 lines
361 B
TypeScript
Raw Normal View History

2024-09-25 19:19:10 +00:00
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;
}