Код: Выделить всё
import polars as pl
df = pl.DataFrame(
{
"dt": [
"2022-12-14T00:00:00", "2022-12-14T00:00:00", "2022-12-14T00:00:00",
],
"seconds": [
1.0, 2.2, 2.4,
],
}
)
df = df.with_columns(pl.col("dt").cast(pl.Datetime))
Код: Выделить всё
df = df.with_columns(pl.col("seconds").cast(pl.Duration).alias("duration0"))
print(df.head())
Код: Выделить всё
┌─────────────────────┬─────────┬──────────────┐
│ dt ┆ seconds ┆ duration0 │
│ --- ┆ --- ┆ --- │
│ datetime[μs] ┆ f64 ┆ duration[μs] │
╞═════════════════════╪═════════╪══════════════╡
│ 2022-12-14 00:00:00 ┆ 1.0 ┆ 0µs │
│ 2022-12-14 00:00:00 ┆ 2.2 ┆ 0µs │
│ 2022-12-14 00:00:00 ┆ 2.4 ┆ 0µs │
└─────────────────────┴─────────┴──────────────┘
Документация по этой теме довольно скудна, есть ли лучшие варианты?
Подробнее здесь: https://stackoverflow.com/questions/748 ... -in-polars