Κοινοποίηση μέσω


lpad

Left-pad the string column to width len with pad.

For the corresponding Databricks SQL function, see lpad function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.lpad(col=<col>, len=<len>, pad=<pad>)

Parameters

Parameter Type Description
col pyspark.sql.Column or str target column to work on.
len pyspark.sql.Column or int length of the final string.
pad pyspark.sql.Column or literal string chars to prepend.

Returns

pyspark.sql.Column: left padded result.

Examples

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('abcd',), ('xyz',), ('12',)], ['s',])
df.select("*", dbf.lpad(df.s, 6, '#')).show()
df = spark.createDataFrame([('abcd',), ('xyz',), ('12',)], ['s',])
df.select("*", dbf.lpad(df.s, 6, dbf.lit(b"\x75\x76"))).show()