Loving the Polars library for its fantastic speed and easy syntax!
Struggling with this question - is there an analogue in Polars for the Pandas code below? Would like to replace strings using a dictionary.
Tried using this expression, but it returns 'TypeError: 'dict' object is not callable'
pl.col("List").str.replace_all(lambda key: key,dict())
In Pandas I would use .replace()
import polars as pl
df = pl.DataFrame({'List': ['Systems', 'Software', 'Cleared']})
mapping = {'Systems':'Sys','Software':'Soft' ,'Cleared':'Clr'}
pl.from_pandas(df.to_pandas().replace(mapping, regex=True))
Output:
shape: (3, 1)
┌──────┐
│ List │
│ --- │
│ str │
╞══════╡
│ Sys │
│ Soft │
│ Clr │
└──────┘