Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Creates a Column of literal value. Supports Spark Connect.
Syntax
from pyspark.sql import functions as dbf
dbf.lit(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column, str, int, float, bool, or list |
The value to make it as a PySpark literal. If a column is passed, it returns the column as is. |
Returns
pyspark.sql.Column: the literal instance.
Examples
Example 1: Creating a literal column with an integer value.
from pyspark.sql import functions as dbf
df = spark.range(1)
df.select(dbf.lit(5).alias('height'), df.id).show()
+------+---+
|height| id|
+------+---+
| 5| 0|
+------+---+
Example 2: Creating a literal column from a list.
from pyspark.sql import functions as dbf
spark.range(1).select(dbf.lit([1, 2, 3])).show()
+--------------+
|array(1, 2, 3)|
+--------------+
| [1, 2, 3]|
+--------------+
Example 3: Creating a literal column from a string.
from pyspark.sql import functions as dbf
df = spark.range(1)
df.select(dbf.lit("PySpark").alias('framework'), df.id).show()
+---------+---+
|framework| id|
+---------+---+
| PySpark| 0|
+---------+---+