polars icon indicating copy to clipboard operation
polars copied to clipboard

expressions everywhere

Open Arengard opened this issue 2 years ago • 5 comments

Problem description

''' df.with_columns([ pl.col("a").str.split("\d{3}").alias("z_a"), pl.col("a").str.replace(pl.col("b"),"").alias("z_b"), pl.col("a")str.extract_all_except(pl.col("b").alias("c_c"), pl.col("a").str.split_exact(pl.col("b").alias("c_d"), pl.col("a")str.replacel(pl.col("b", "").alias("c_c"), ] ) '''

Arengard avatar Dec 14 '22 21:12 Arengard

What is your suggestion?

If you don't want to type pl.col, you are free to rename it. It is your program.

import polars.col as c

ritchie46 avatar Dec 14 '22 21:12 ritchie46

You could create variables:

a = pl.col("a").str
b = pl.col("b")

df.with_columns([
   a.split().alias(),
   a.replace().alias(),
   a.extract_all().alias(),
   ...
])

cmdlineluser avatar Dec 14 '22 21:12 cmdlineluser

I typically use this preamble:

import polars as pl
from polars import col, when

This cleans up syntax a lot:

df.select([
    when(col('a').is_in(col('b')).then(1)
    .otherwise(2)
])

...etc.

mcrumiller avatar Dec 14 '22 21:12 mcrumiller

we as of now cant do ny of the operation from obove

Arengard avatar Dec 14 '22 22:12 Arengard

Can you spend a little more effort describing what your issue is?

mcrumiller avatar Dec 14 '22 22:12 mcrumiller

I will close this issue as I don't see anything constructive here. If there is a better definition of the problem, a suggestion how to fix it and more effort to fill in our issue templates feel free to open a new issue.

ritchie46 avatar Dec 20 '22 12:12 ritchie46