Polars: Create Column with Fixed Value from Variable

Polars: Create Column with Fixed Value from Variable

I have scrubbed the polars docs and cannot see an example of creating a column with a fixed value from a variable. Here is what works in pandas:

df['VERSION'] = version

Thx

1 Answer

Use polars.lit

import polars as pl

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.