We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hey there, wasn't sure where best to respond but I just thought I'd share some info I've learned as a Polars user which may be of interest:
For to the convert a string to a datetime example:
convert a string to a datetime
df.with_columns(dt = pl.col('string_date').str.to_datetime().cast(pl.Datetime))
Perhaps the .cast() is a stray from previous examples, but you already have a datetime so it can be omitted.
.cast()
datetime
df.with_columns(dt = pl.col('string_date').str.to_datetime())
dt.date() can also be used to get a date from a datetime
dt.date()
date
df.with_columns( pl.col('string_date').str.to_datetime().dt.date() )
I’m curious what happens if I simply just .cast('date')
.cast('date')
This has been requested, there is a pending PR: pola-rs/polars#10517
[Update]: This was added in pola-rs/polars#12072
I’ll be buggered if I know the difference between to_datetime() and strptime()
to_datetime()
strptime()
They are essentially aliases, to_date() / to_datetime() were added later and str.strptime() remains for legacy reasons.
to_date()
str.strptime()
str.strptime
dt.strftime
This is why .to_datetime() lives under .str but you do bring up an interesting point as the new name doesn't imply it is tied to strings.
.to_datetime()
.str
It should be simply pl.col('column').to_datetime() and error if the data types are wrong
pl.col('column').to_datetime()
Similar to the strptime case, .dt.to_string() was added as an alias in favour of .dt.strftime()
strptime
.dt.to_string()
.dt.strftime()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hey there, wasn't sure where best to respond but I just thought I'd share some info I've learned as a Polars user which may be of interest:
For to the
convert a string to a datetime
example:Perhaps the
.cast()
is a stray from previous examples, but you already have adatetime
so it can be omitted.dt.date()
dt.date()
can also be used to get adate
from adatetime
pl.col("foo").cast(pl.Date)
This has been requested,
there is a pending PR: pola-rs/polars#10517[Update]: This was added in pola-rs/polars#12072
.strptime()
They are essentially aliases,
to_date()
/to_datetime()
were added later andstr.strptime()
remains for legacy reasons.str.strptime
/dt.strftime
methods pola-rs/polars#8215This is why
.to_datetime()
lives under.str
but you do bring up an interesting point as the new name doesn't imply it is tied to strings..dt.to_string()
Similar to the
strptime
case,.dt.to_string()
was added as an alias in favour of.dt.strftime()
The text was updated successfully, but these errors were encountered: