pyspark.sql.functions.initcap#

pyspark.sql.functions.initcap(col)[source]#

Translate the first letter of each word to upper case in the sentence.

Added in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
colColumn or column name

target column to work on. A column that evaluates to a string.

Returns:
Column

string with all first letters are uppercase in each word. Returns a column that evaluates to a string.

Examples

>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([('ab cd',)], ['a'])
>>> df.select("*", sf.initcap("a")).show()
+-----+----------+
|    a|initcap(a)|
+-----+----------+
|ab cd|     Ab Cd|
+-----+----------+