-
-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Ability to perform custom operations by using the map and apply functions
Feature demonstration with expected result
I would like to have the ability to perform a custom operation on a Series/Expr as such:
import pl from 'nodejs-polars';
const data = [
{ a: 'A', b: 10},
{ a: 'B', b: 20},
{ a: 'B', b: 13},
{ a: 'C', b: 40},
];
const mapping = { D: 'OtherD'};
const df = pl.DataFrame(data);
const dfWithOtherA = df.withColumns([pl.col("a").map((val) => mapping[val]).alias('otherA')]);
/* expected result:
┌─────┬──────┬────────┐
│ a ┆ b ┆ otherA │
│ --- ┆ --- ┆ --- │
│ str ┆ f64 ┆ str │
╞═════╪══════╪════════╡
│ A ┆ 10.0 ┆ A │
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ B ┆ 20.0 ┆ OtherB │
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ B ┆ 13.0 ┆ OtherB │
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ C ┆ 40.0 ┆ C │
└─────┴──────┴────────┘
*/The expected behavior should follow what is described in the polars docs.
Other comments
I would be happy to help with some guidance, but I still am not aware of polars internals to go for a PR.
Thank you for the awesome work in all other APIs and functions, keep the great work! :)
ChakshuGautam, sezanzeb, kevinschaich, sylc, SYip and 12 morema9o
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request