PySpark SQL Functions | lit method
PySpark SQL Functions'
lit(~) method creates a
Column object with the specified value.
A value to fill the column.
Consider the following PySpark DataFrame:
Creating a column of constants in PySpark DataFrame
To create a new PySpark DataFrame with the
name column of
df and a new column called
is_single made up of
F.lit(True) returns a
Column object, which has a method called
alias(~) that assigns a label.
Note that you could append a new column of constants using the
Creating a column whose values are based on a condition in PySpark
We can also use
lit(~) to create a column whose values depend on some condition:
Note the following: