【问题标题】:How to add a column to a polars DataFrame using .with_columns()如何使用 .with_columns() 将列添加到 Polars DataFrame
【发布时间】:2022-08-24 20:05:23
【问题描述】:

我目前正在使用 Polars 数据框中创建一个新列

df[\'predictions\'] = predictions

包含我用另一个工具计算的值。

但是,polars 会发出警告,表示此选项将被弃用。 如何使用.with_columns() 获得相同的结果?

标签: python-polars


【解决方案1】:

对于极坐标中的 with_column\with_columns,请按以下方式应用该函数:

import polars as pl
df = df.with_column(pl.lit('predictions').alias('predictions'))

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 1970-01-01
    • 2023-01-28
    • 2021-06-26
    • 2015-10-15
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多