Below is a sample of my data in which i have ten string columns that i need to cast to duration then to seconds (int32)
I have tried using pl.str.strptime
and cast(pl.Duration)
but all failed
import polars as pl
df = pl.DataFrame(
{
"a" : ["24:00:00" , "00:45:00"]
}
)
df.with_columns(
pl.col("a").str.strptime(pl.Duration, "%H:%M:%S")
)
The first value should be 86400 and the second should be 2700.
I came from power query where I can just replace "24:00:00"
with "1.0:00:00"
and change the type to duration.
Any suggested solution?
Thanks in advance.
Based on @jqurious comment above, I have succeeded in converting it to duration by extract string to list then get list members and assign it to duratio then to int seconds as follow:
However, I couldn't apply this solution on multi column which is my data case:
As a workaround, I have succeeded converting it directly to int seconds: