-werners-
Esteemed Contributor III

That is totally possible.
f.e. here is a function that trims all string columns in a dataframe.  You can change it to your needs:

def trim_all_string_columns(df: dataframe) -> dataframe:
        for c in df.schema.fields:
            if isinstance(c.dataType, StringType):
                df = df.withColumn(c.name, F.trim(F.col(c.name)))
        return df

View solution in original post