-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add padding method to List datatype #10283
Comments
I discussed this with @ritchie46 and we think it's a reasonable request. |
In the mean time you could do something like this: df = pl.DataFrame(ser)
(df
.with_columns(pl.lit(0).alias('pad_value'))
.with_columns(
pl.concat_list(
pl.col('pad_value').repeat_by(5 - pl.col('column_0').list.lengths()),
'column_0')
.alias('column_0'))
.drop('pad_value')) |
Related issue that was suggest by @ritchie46 (extend_constant): #2810 |
@reswqa as discussed. Free to pick up. :) |
@ritchie46 I want to do it myself :) Can I? |
@balakhaniyan Of course, feel free to pick this up. ritchie and I will help review the code then. |
Would love this feature! I often need it for machine learning purpose Can't believe string has pad_end and pad_start feature but list doesn't have it yet I may be able to help, but I'm new to this kind of thing, not sure where to look the polars/py-polars/polars/expr/string.py Line 847 in 5f6bc77
Searched py-polars/polars/expr/expr.py but there doesn't seem to be a function called str_pad_start |
It is in rust, under |
It calls
df = s.to_frame("x")
df.with_columns(
pl.lit(0).repeat_by(5 - pl.col("x").list.len())
.list.concat("x")
.alias("list.pad_start")
)
# shape: (3, 2)
# ┌─────────────────┬─────────────────┐
# │ x ┆ list.pad_start │
# │ --- ┆ --- │
# │ list[i64] ┆ list[i64] │
# ╞═════════════════╪═════════════════╡
# │ [1, 2, 3, 4] ┆ [0, 1, 2, 3, 4] │
# │ [2, 3, 4, 5, 6] ┆ [2, 3, 4, 5, 6] │
# │ [3, 2, 1] ┆ [0, 0, 3, 2, 1] │
# └─────────────────┴─────────────────┘ |
Sorry, can't help with that, I'm not familiar enough with Rust 😅 I spouted my previous comment spontaneously, forgetting that Polars core is written in Rust |
@AndhikaWB if you try, you will learn it ;) |
Problem description
Is it possible to add a method to
list
class so we can justify (pad) list just like str?example:
It could have more feature like clipping lists with greater length.
The text was updated successfully, but these errors were encountered: