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
Use polars.lit
import polars as pl
version = 6
df = df.with_columns(pl.lit(version).alias('VERSION'))
How to add new column to Latest (2024) Polars DataFrame:
In this example we are adding a uuid column to dataframe
import uuid
import polars as pl
# Generate a UUID
uuid = str(uuid.uuid4())
# Add a new column with the generated UUID to the DataFrame
df = df.with_columns(uuid=pl.lit(uuid))
Doc:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With