[Python] Polars YYYY week into a date

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

  1. Stack

    Stack Membro Participativo

    Does anyone know how to parse YYYY Week into a date column in Polars?
    I have tried this code but it throws an error.

    import polars as pl

    pl.DataFrame({
    "week": [201901, 201902, 201903, 201942, 201943, 201944]
    }).with_columns(pl.col("week").cast(pl.String).str.to_date("%Y%U").alias("date"))


    InvalidOperationError: conversion from `str` to `date` failed in column 'week'
    for 6 out of 6 values: ["201901", "201902", … "201944"]

    Continue reading...

Compartilhe esta Página