我已经仔细查看了 polars
的文档,但没有找到一个用变量创建一个固定值列的示例。以下是在 pandas
中有效的方法:
df['VERSION'] = version
谢谢
我已经仔细查看了 polars
的文档,但没有找到一个用变量创建一个固定值列的示例。以下是在 pandas
中有效的方法:
df['VERSION'] = version
谢谢
polars.lit
。import polars as pl
version = 6
df = df.with_columns(pl.lit(version).alias('VERSION'))
lit
表达式的一些文档:https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.lit.html - user18263465with_columns()
是正确的方法,with_column
会抛出错误。 - abk