[Python] Converting string to DateTime Polars

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    I have a Polars dataframe with a column of type str with the date and time

    df = pl.from_repr("""
    ┌─────────────────────────┐
    │ EventTime │
    │ --- │
    │ str │
    ╞═════════════════════════╡
    │ 2020-03-02T13:10:42.550 │
    └─────────────────────────┘
    """)


    I want to convert this column to the polars.Datetime type.

    After reading this post Easily convert string column to pl.datetime in Polars, I came up with:

    df = df.with_columns(pl.col('EventTime').str.to_datetime("%Y-%m-%dT%H:%M:%f", strict=False))


    However, the values my column "EventTime' are all null.

    Many Thanks!

    Continue reading...

Compartilhe esta Página