Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract date from weirdly formatted datetime polars

import polars as pl
df = pl.DataFrame(['2023-08-01T06:13:24.448409',
'2023-08-01T07:29:34.491027'])

print(df.with_columns(pl.col('column_0').str.strptime(pl.Date,'%Y-%m-%d')))

So I have the following mass of code, and for some ungodly reason I cant for the death of me extract the date from those given strings.

In the following example I keep getting the error

exceptions.ComputeError: strict date parsing failed for 2 value(s) (2 unique): ["2023-08-01T06:13:24.448409", "2023-08-01T07:29:34.491027"]

Any ideas on how can I extract the string from such format of datetime? And why I get this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To parse a datetime upfront you’ll need to provide the full format (date & time) initially then retrieve the date part afterwards. Try the following format:

'%Y-%m-%dT%H:%M:%S.%f'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading