Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a column to a polars DataFrame using .with_columns()

I am currently creating a new column in a polars data frame using

predictions = [10, 20, 30, 40, 50]
df['predictions'] = predictions

where predictions is a numpy array or list containing values I computed with another tool.

However, polars throws a warning, that this option will be deprecated. How can the same result be achieved using .with_columns()?

like image 624
Felix.B Avatar asked Sep 06 '25 00:09

Felix.B


1 Answers

The values in the numpy array or list predictions can be add to a polars table using:

predictions = [10, 20, 30, 40, 50]
df.with_columns(pl.Series(name="predictions", values=predictions)) 
like image 85
Felix.B Avatar answered Sep 08 '25 14:09

Felix.B