9

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()?

Felix.B
  • 306
  • 2
  • 8
  • This should answer your question: https://stackoverflow.com/questions/72245243/polars-how-to-add-a-column-with-numerical/72245435#72245435 –  Aug 01 '22 at 13:15
  • 1
    Thankd, yes that answers it. IMO it would be great to add the linked answer to the "Coming from Pandas" guide: https://pola-rs.github.io/polars-book/user-guide/coming_from_pandas.html – Felix.B Aug 01 '22 at 13:57
  • 1
    It is there, see https://pola-rs.github.io/polars-book/user-guide/coming_from_pandas.html#column-assignment – jvz Aug 01 '22 at 20:05

1 Answers1

17

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_column(pl.Series(name="predictions", values=predictions)) 
Felix.B
  • 306
  • 2
  • 8