Код: Выделить всё
df = pl.DataFrame({
'date': ['2022-01-01', '2022-02-01', '2022-03-01']
})
df.with_column(pl.col('date').str.strptime(pl.Date, fmt='%Y-%m').cast(pl.Datetime)).alias('year-month')
дата
01.01.2022
01.02.2022< /td>
01.03.2022
Желаемый результат:
дата
год-месяц
01.01.2022
2022-01
2022-02-01
2022-02
2022-03-01
2022-03
Я пробовал:
Код: Выделить всё
df.with_column(pl.col('date').str.strptime(pl.Date, fmt='%Y-%m').cast(pl.Datetime)).alias('year-month')
SchemaError: недопустимая серия dtype: ожидается Utf8, получено datetime[ns]
Большое спасибо!!!
Подробнее здесь: https://stackoverflow.com/questions/759 ... -dataframe
Мобильная версия