PySpark SQL Functions | trim method
PySpark SQL Functions'
trim(~) method returns a new PySpark column with the string values trimmed, that is, with the leading and trailing spaces removed.
The column of type
string to trim.
A new PySpark Column.
Consider the following PySpark DataFrame:
Here, the values in the
name column have leading and trailing spaces.
Trimming columns in PySpark
To trim the
name column, that is, to remove the leading and trailing spaces:
alias(~) method is used to assign a label to the
Column returned by
To get the original PySpark DataFrame but with the
name column updated with the trimmed version, use the