Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Polars Customized Function Returns Multiple Columns

$
0
0

_func is designed to return two columns:

from polars.type_aliases import IntoExpr, IntoExprColumnimport polars as pldef _func(x: IntoExpr):    x1 = x+1    x2 = x+2    return pl.struct([x1, x2])df = pl.DataFrame({"test": np.arange(1, 11)})df.with_columns(    _func(pl.col("test")).alias(["test1", "test2"]))

I have tried to wrap the return values using pl.struct but it didn't work.

Expected output:

shape: (10, 3)test test1 test2i32 i32 i321   2   32   3   43   4   54   5   65   6   76   7   87   8   98   9   109   10  1110  11  12

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>