pyspark.sql.functions.rpad#
- pyspark.sql.functions.rpad(col, len, pad)[source]#
Right-pad the string column to width len with pad.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- Returns
Column
right padded result.
See also
Examples
Example 1: Pad with a literal string
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([('abcd',), ('xyz',), ('12',)], ['s',]) >>> df.select("*", sf.rpad(df.s, 6, '#')).show() +----+-------------+ | s|rpad(s, 6, #)| +----+-------------+ |abcd| abcd##| | xyz| xyz###| | 12| 12####| +----+-------------+
Example 2: Pad with a bytes column
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([('abcd',), ('xyz',), ('12',)], ['s',]) >>> df.select("*", sf.rpad(df.s, 6, sf.lit(b"uv"))).show() +----+-------------------+ | s|rpad(s, 6, X'7576')| +----+-------------------+ |abcd| abcduv| | xyz| xyzuvu| | 12| 12uvuv| +----+-------------------+