I have a polars dataframe that contains a datetime
column. I want to convert this column to strings in the format %Y%m
. For example, all dates in January 2024 should be converted to "202401"
.
from datetime import datetime
import polars as pl
data = {
"ID" : [1,2,3],
"dates" : [datetime(2024,1,2),datetime(2024,1,3),datetime(2024,1,4)],
}
df = pl.DataFrame(data)
I have tried using strftime
. However, the following AttributeError
is raised.
AttributeError: 'Expr' object has no attribute 'strftime'