[Python] Polars Dataframe : Date conversion of String column

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

  1. Stack

    Stack Membro Participativo

    I am trying to convert a str column in the DataFrame into Date format of YYYY-MM-DD. How to convert different date format into one format of YYYY-MM-DD?

    s = pl.Series("date",["Sun Jul 8 00:34:60 2001", "12Mar2022", "12/Mar/2022"])

    df = s.to_frame().with_columns(pl.col("date").str.to_date("%d%m%Y", strict=False))


    shape: (3, 1)
    ┌──────┐
    │ date │
    │ --- │
    │ date │
    ╞══════╡
    │ null │
    │ null │
    │ null │
    └──────┘

    Continue reading...

Compartilhe esta Página