Существующее имя столбца — starttime. Этот столбец содержит строку даты и времени.
Код: Выделить всё
import polars as pl
df = pl.from_repr("""
┌─────────────────────┬─────────────────────┬────────────┬───────────┬─────────┐
│ starttime ┆ endtime ┆ storageid ┆ volume_id ┆ avgiops │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ i64 │
╞═════════════════════╪═════════════════════╪════════════╪═══════════╪═════════╡
│ 2022-02-10 09:32:20 ┆ 2022-02-10 09:34:28 ┆ TUNYKYPG72 ┆ 4c8d6c31 ┆ 27 │
│ 2022-02-10 10:34:10 ┆ 2022-02-10 10:35:12 ┆ TUNYKYPG42 ┆ 4c8d6d31 ┆ 34 │
└─────────────────────┴─────────────────────┴────────────┴───────────┴─────────┘
""")
Код: Выделить всё
df.with_columns(
pl.col('starttime').str.to_datetime('%Y').alias('year')
)
Код: Выделить всё
InvalidOperationError: conversion from `str` to `date` failed in column 'starttime'
Подробнее здесь: https://stackoverflow.com/questions/751 ... -in-polars
Мобильная версия