极光:从变量中创建具有固定值的列

16

我已经仔细查看了 polars 的文档,但没有找到一个用变量创建一个固定值列的示例。以下是在 pandas 中有效的方法:

df['VERSION'] = version

谢谢

1个回答

34
使用 polars.lit
import polars as pl

version = 6
df = df.with_columns(pl.lit(version).alias('VERSION'))

1
这是关于 lit 表达式的一些文档:https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.lit.html - user18263465
感谢@cbilot的快速回复。尝试将所有pandas的代码进行提取、转换和加载到数据库中,以便进行polars迁移。 - rchitect-of-info
2
with_columns() 是正确的方法,with_column 会抛出错误。 - abk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接