I want to strip a dataframe based on its data type per column. If it is a string column, a strip should be executed. If it is not a string column, it should not be striped. In pandas there is the following approach for this task:
df_clean = df_select.copy()
for col in df_select.columns:
if df_select[col].dtype == 'object':
df_clean[col] = df_select[col].str.strip()
How can this be executed in polars?
import polars as pl
df = pl.DataFrame(
{
"ID": [1, 1, 1, 1,],
"A": ["foo ", "ham", "spam ", "egg",],
"L": ["A54", " A12", "B84", " C12"],
}
)