Reputation: 417
I want to strip leading and trailing whitespaces from a polars dataframe with this line of code:
df = pl.DataFrame(
{
"A": ["foo ", "ham", "spam ", "egg",],
"L": ["A54", " A12", "B84", " C12"],
}
)
print(df)
shape: (4, 2)
┌───────┬──────┐
│ A ┆ L │
│ --- ┆ --- │
│ str ┆ str │
╞═══════╪══════╡
│ foo ┆ A54 │
│ ham ┆ A12 │
│ spam ┆ B84 │
│ egg ┆ C12 │
└───────┴──────┘
df_clean = df.select(
[pl.all().map(lambda x: x.strip() if isinstance(x, str) else x)]
)
But it did not work. How can I strip an entire polars dataframe?
Upvotes: 2
Views: 3508
Reputation: 66
.str.strip()
is deprecated now.
.str.strip_chars()
should be used instead.
Upvotes: 5