PySpark Column | alias method
alias(~) method assigns a column label to a PySpark
The column label.
A dictionary holding additional meta-information to store in the
StructField of the returned
A new PySpark Column.
Consider the following PySpark DataFrame:
Most methods in the
PySpark SQL Functions library return
Column objects whose label is governed by the method that we use. For instance, consider the
Here, the PySpark Column returned by
lower(~) has the label
lower(name) by default.
Assigning new label to PySpark Column using the alias method
We can assign a new label to a column by using the
Here, we have assigned the label
"lower_name" to the column returned by
Storing meta-data in PySpark Column's alias method
To store some meta-data in a PySpark Column, we can add the
metadata option in
metadata is a dictionary that will be stored in the
To access the
metadata, we can use the PySpark DataFrame's